IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
FieldInfo.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2009-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*/
24using System.Collections.Generic;
25
26namespace IKVM.Reflection
27{
28
29 internal abstract class FieldInfo : MemberInfo
30 {
31
35 internal FieldInfo()
36 {
37
38 }
39
40 public sealed override MemberTypes MemberType
41 {
42 get { return MemberTypes.Field; }
43 }
44
45 public abstract FieldAttributes Attributes { get; }
46
47 public abstract object GetRawConstantValue();
48
49 internal abstract FieldSignature FieldSignature { get; }
50
51 public Type FieldType
52 {
53 get { return this.FieldSignature.FieldType; }
54 }
55
56 public CustomModifiers __GetCustomModifiers()
57 {
58 return this.FieldSignature.GetCustomModifiers();
59 }
60
61 public Type[] GetOptionalCustomModifiers()
62 {
63 return __GetCustomModifiers().GetOptional();
64 }
65
66 public Type[] GetRequiredCustomModifiers()
67 {
68 return __GetCustomModifiers().GetRequired();
69 }
70
71 public bool IsStatic
72 {
73 get { return (Attributes & FieldAttributes.Static) != 0; }
74 }
75
76 public bool IsLiteral
77 {
78 get { return (Attributes & FieldAttributes.Literal) != 0; }
79 }
80
81 public bool IsInitOnly
82 {
83 get { return (Attributes & FieldAttributes.InitOnly) != 0; }
84 }
85
86 public bool IsNotSerialized
87 {
88 get { return (Attributes & FieldAttributes.NotSerialized) != 0; }
89 }
90
91 public bool IsSpecialName
92 {
93 get { return (Attributes & FieldAttributes.SpecialName) != 0; }
94 }
95
96 public bool IsPublic
97 {
98 get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public; }
99 }
100
101 public bool IsPrivate
102 {
103 get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private; }
104 }
105
106 public bool IsFamily
107 {
108 get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family; }
109 }
110
111 public bool IsFamilyOrAssembly
112 {
113 get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem; }
114 }
115
116 public bool IsAssembly
117 {
118 get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly; }
119 }
120
121 public bool IsFamilyAndAssembly
122 {
123 get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem; }
124 }
125
126 public bool IsPinvokeImpl
127 {
128 get { return (Attributes & FieldAttributes.PinvokeImpl) != 0; }
129 }
130
131 public virtual FieldInfo __GetFieldOnTypeDefinition()
132 {
133 return this;
134 }
135
136 public abstract bool __TryGetFieldOffset(out int offset);
137
138 public bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
139 {
140 return FieldMarshal.ReadFieldMarshal(this.Module, GetCurrentToken(), out fieldMarshal);
141 }
142
143 internal abstract int ImportTo(Emit.ModuleBuilder module);
144
145 internal virtual FieldInfo BindTypeParameters(Type type)
146 {
147 return new GenericFieldInstance(this.DeclaringType.BindTypeParameters(type), this);
148 }
149
150 internal sealed override bool BindingFlagsMatch(BindingFlags flags)
151 {
152 return BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
153 && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static, BindingFlags.Instance);
154 }
155
156 internal sealed override bool BindingFlagsMatchInherited(BindingFlags flags)
157 {
158 return (Attributes & FieldAttributes.FieldAccessMask) > FieldAttributes.Private
159 && BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
160 && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static | BindingFlags.FlattenHierarchy, BindingFlags.Instance);
161 }
162
163 internal sealed override MemberInfo SetReflectedType(Type type)
164 {
165 return new FieldInfoWithReflectedType(type, this);
166 }
167
168 internal sealed override List<CustomAttributeData> GetPseudoCustomAttributes(Type attributeType)
169 {
170 var module = Module;
171 var list = new List<CustomAttributeData>();
172
173 if (attributeType == null || attributeType.IsAssignableFrom(Module.Universe.System_Runtime_InteropServices_MarshalAsAttribute))
174 if (__TryGetFieldMarshal(out var spec))
175 list.Add(CustomAttributeData.CreateMarshalAsPseudoCustomAttribute(module, spec));
176
177 if (attributeType == null || attributeType.IsAssignableFrom(Module.Universe.System_Runtime_InteropServices_FieldOffsetAttribute))
178 if (__TryGetFieldOffset(out var offset))
179 list.Add(CustomAttributeData.CreateFieldOffsetPseudoCustomAttribute(module, offset));
180
181 return list;
182 }
183
184 }
185
186}
IKVM.Reflection.Module Module
IKVM.Reflection.Type Type
IKVM.Reflection.FieldInfo FieldInfo
IKVM.Reflection.MemberInfo MemberInfo