IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
MissingField.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2011-2012 Jeroen Frijters
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
19
20 Jeroen Frijters
21 jeroen@frijters.net
22
23*/
24namespace IKVM.Reflection
25{
26 sealed class MissingField : FieldInfo
27 {
28
29 readonly Type declaringType;
30 readonly string name;
31 readonly FieldSignature signature;
32 FieldInfo forwarder;
33
40 internal MissingField(Type declaringType, string name, FieldSignature signature)
41 {
42 this.declaringType = declaringType;
43 this.name = name;
44 this.signature = signature;
45 }
46
47 FieldInfo Forwarder => TryGetForwarder() ?? throw new MissingMemberException(this);
48
49 FieldInfo TryGetForwarder()
50 {
51 if (forwarder == null && !declaringType.__IsMissing)
52 forwarder = declaringType.FindField(name, signature);
53
54 return forwarder;
55 }
56
57 public override bool __IsMissing
58 {
59 get { return TryGetForwarder() == null; }
60 }
61
62 public override FieldAttributes Attributes
63 {
64 get { return Forwarder.Attributes; }
65 }
66
67 public override bool __TryGetFieldOffset(out int offset)
68 {
69 return Forwarder.__TryGetFieldOffset(out offset);
70 }
71
72 public override object GetRawConstantValue()
73 {
74 return Forwarder.GetRawConstantValue();
75 }
76
77 internal override FieldSignature FieldSignature
78 {
79 get { return signature; }
80 }
81
82 internal override int ImportTo(IKVM.Reflection.Emit.ModuleBuilder module)
83 {
84 var field = TryGetForwarder();
85 if (field != null)
86 return field.ImportTo(module);
87
88 return module.ImportMethodOrField(declaringType, this.Name, this.FieldSignature);
89 }
90
91 public override string Name
92 {
93 get { return name; }
94 }
95
96 public override Type DeclaringType
97 {
98 get { return declaringType.IsModulePseudoType ? null : declaringType; }
99 }
100
101 public override Module Module
102 {
103 get { return declaringType.Module; }
104 }
105
106 internal override FieldInfo BindTypeParameters(Type type)
107 {
108 var forwarder = TryGetForwarder();
109 if (forwarder != null)
110 return forwarder.BindTypeParameters(type);
111
112 return new GenericFieldInstance(type, this);
113 }
114
115 public override int MetadataToken
116 {
117 get { return Forwarder.MetadataToken; }
118 }
119
120 public override bool Equals(object obj)
121 {
122 var other = obj as MissingField;
123 return other != null
124 && other.declaringType == declaringType
125 && other.name == name
126 && other.signature.Equals(signature);
127 }
128
129 public override int GetHashCode()
130 {
131 return declaringType.GetHashCode() ^ name.GetHashCode() ^ signature.GetHashCode();
132 }
133
134 public override string ToString()
135 {
136 return FieldType.Name + " " + Name;
137 }
138
139 internal override int GetCurrentToken()
140 {
141 return Forwarder.GetCurrentToken();
142 }
143
144 internal override bool IsBaked
145 {
146 get { return Forwarder.IsBaked; }
147 }
148
149 }
150
151}
global::java.lang.invoke.LambdaForm.Name Name
override bool Equals(object obj)
override object GetRawConstantValue()
override bool __TryGetFieldOffset(out int offset)
override bool Equals(object obj)
override FieldAttributes Attributes