mscorlib(4.0.0.0) API with additions
FieldInfo.cs
1 using System.Diagnostics;
5 
6 namespace System.Reflection
7 {
10  [ClassInterface(ClassInterfaceType.None)]
11  [ComDefaultInterface(typeof(_FieldInfo))]
12  [ComVisible(true)]
13  [__DynamicallyInvokable]
14  [PermissionSet(SecurityAction.InheritanceDemand, Name = "FullTrust")]
15  public abstract class FieldInfo : MemberInfo, _FieldInfo
16  {
19  public override MemberTypes MemberType => MemberTypes.Field;
20 
23  [__DynamicallyInvokable]
24  public abstract RuntimeFieldHandle FieldHandle
25  {
26  [__DynamicallyInvokable]
27  get;
28  }
29 
32  [__DynamicallyInvokable]
33  public abstract Type FieldType
34  {
35  [__DynamicallyInvokable]
36  get;
37  }
38 
41  [__DynamicallyInvokable]
42  public abstract FieldAttributes Attributes
43  {
44  [__DynamicallyInvokable]
45  get;
46  }
47 
51  [__DynamicallyInvokable]
52  public bool IsPublic
53  {
54  [__DynamicallyInvokable]
55  get
56  {
57  return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public;
58  }
59  }
60 
64  [__DynamicallyInvokable]
65  public bool IsPrivate
66  {
67  [__DynamicallyInvokable]
68  get
69  {
70  return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private;
71  }
72  }
73 
77  [__DynamicallyInvokable]
78  public bool IsFamily
79  {
80  [__DynamicallyInvokable]
81  get
82  {
83  return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family;
84  }
85  }
86 
90  [__DynamicallyInvokable]
91  public bool IsAssembly
92  {
93  [__DynamicallyInvokable]
94  get
95  {
96  return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly;
97  }
98  }
99 
103  [__DynamicallyInvokable]
104  public bool IsFamilyAndAssembly
105  {
106  [__DynamicallyInvokable]
107  get
108  {
109  return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem;
110  }
111  }
112 
116  [__DynamicallyInvokable]
117  public bool IsFamilyOrAssembly
118  {
119  [__DynamicallyInvokable]
120  get
121  {
122  return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem;
123  }
124  }
125 
129  [__DynamicallyInvokable]
130  public bool IsStatic
131  {
132  [__DynamicallyInvokable]
133  get
134  {
135  return (Attributes & FieldAttributes.Static) != FieldAttributes.PrivateScope;
136  }
137  }
138 
142  [__DynamicallyInvokable]
143  public bool IsInitOnly
144  {
145  [__DynamicallyInvokable]
146  get
147  {
148  return (Attributes & FieldAttributes.InitOnly) != FieldAttributes.PrivateScope;
149  }
150  }
151 
155  [__DynamicallyInvokable]
156  public bool IsLiteral
157  {
158  [__DynamicallyInvokable]
159  get
160  {
161  return (Attributes & FieldAttributes.Literal) != FieldAttributes.PrivateScope;
162  }
163  }
164 
168  public bool IsNotSerialized => (Attributes & FieldAttributes.NotSerialized) != FieldAttributes.PrivateScope;
169 
173  [__DynamicallyInvokable]
174  public bool IsSpecialName
175  {
176  [__DynamicallyInvokable]
177  get
178  {
179  return (Attributes & FieldAttributes.SpecialName) != FieldAttributes.PrivateScope;
180  }
181  }
182 
186  public bool IsPinvokeImpl => (Attributes & FieldAttributes.PinvokeImpl) != FieldAttributes.PrivateScope;
187 
191  public virtual bool IsSecurityCritical => FieldHandle.IsSecurityCritical();
192 
196  public virtual bool IsSecuritySafeCritical => FieldHandle.IsSecuritySafeCritical();
197 
201  public virtual bool IsSecurityTransparent => FieldHandle.IsSecurityTransparent();
202 
208  [__DynamicallyInvokable]
210  {
211  if (handle.IsNullHandle())
212  {
213  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
214  }
215  FieldInfo fieldInfo = RuntimeType.GetFieldInfo(handle.GetRuntimeFieldInfo());
216  Type declaringType = fieldInfo.DeclaringType;
217  if (declaringType != null && declaringType.IsGenericType)
218  {
219  throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_FieldDeclaringTypeGeneric"), fieldInfo.Name, declaringType.GetGenericTypeDefinition()));
220  }
221  return fieldInfo;
222  }
223 
231  [ComVisible(false)]
232  [__DynamicallyInvokable]
234  {
235  if (handle.IsNullHandle())
236  {
237  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
238  }
239  return RuntimeType.GetFieldInfo(declaringType.GetRuntimeType(), handle.GetRuntimeFieldInfo());
240  }
241 
247  [__DynamicallyInvokable]
248  public static bool operator ==(FieldInfo left, FieldInfo right)
249  {
250  if ((object)left == right)
251  {
252  return true;
253  }
254  if ((object)left == null || (object)right == null || left is RuntimeFieldInfo || right is RuntimeFieldInfo)
255  {
256  return false;
257  }
258  return left.Equals(right);
259  }
260 
266  [__DynamicallyInvokable]
267  public static bool operator !=(FieldInfo left, FieldInfo right)
268  {
269  return !(left == right);
270  }
271 
276  [__DynamicallyInvokable]
277  public override bool Equals(object obj)
278  {
279  return base.Equals(obj);
280  }
281 
284  [__DynamicallyInvokable]
285  public override int GetHashCode()
286  {
287  return base.GetHashCode();
288  }
289 
292  public virtual Type[] GetRequiredCustomModifiers()
293  {
294  throw new NotImplementedException();
295  }
296 
299  public virtual Type[] GetOptionalCustomModifiers()
300  {
301  throw new NotImplementedException();
302  }
303 
308  [CLSCompliant(false)]
309  public virtual void SetValueDirect(TypedReference obj, object value)
310  {
311  throw new NotSupportedException(Environment.GetResourceString("NotSupported_AbstractNonCLS"));
312  }
313 
320  [CLSCompliant(false)]
321  public virtual object GetValueDirect(TypedReference obj)
322  {
323  throw new NotSupportedException(Environment.GetResourceString("NotSupported_AbstractNonCLS"));
324  }
325 
333  [__DynamicallyInvokable]
334  public abstract object GetValue(object obj);
335 
341  public virtual object GetRawConstantValue()
342  {
343  throw new NotSupportedException(Environment.GetResourceString("NotSupported_AbstractNonCLS"));
344  }
345 
355  public abstract void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture);
356 
365  [DebuggerStepThrough]
366  [DebuggerHidden]
367  [__DynamicallyInvokable]
368  public void SetValue(object obj, object value)
369  {
370  SetValue(obj, value, BindingFlags.Default, Type.DefaultBinder, null);
371  }
372 
376  {
377  return GetType();
378  }
379 
383  void _FieldInfo.GetTypeInfoCount(out uint pcTInfo)
384  {
385  throw new NotImplementedException();
386  }
387 
393  void _FieldInfo.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
394  {
395  throw new NotImplementedException();
396  }
397 
405  void _FieldInfo.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
406  {
407  throw new NotImplementedException();
408  }
409 
420  void _FieldInfo.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
421  {
422  throw new NotImplementedException();
423  }
424  }
425 }
void GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
Retrieves the type information for an object, which can then be used to get the type information for ...
Obtains information about the attributes of a member and provides access to member metadata.
Definition: MemberInfo.cs:14
bool IsNotSerialized
Gets a value indicating whether this field has the NotSerialized attribute.
Definition: FieldInfo.cs:168
virtual Type GetGenericTypeDefinition()
Returns a T:System.Type object that represents a generic type definition from which the current gener...
Definition: Type.cs:2443
bool IsSpecialName
Gets a value indicating whether the corresponding SpecialName attribute is set in the T:System....
Definition: FieldInfo.cs:175
bool IsLiteral
Gets a value indicating whether the value is written at compile time and cannot be changed.
Definition: FieldInfo.cs:157
bool IsStatic
Gets a value indicating whether the field is static.
Definition: FieldInfo.cs:131
abstract Type FieldType
Gets the type of this field object.
Definition: FieldInfo.cs:34
void GetTypeInfoCount(out uint pcTInfo)
Retrieves the number of type information interfaces that an object provides (either 0 or 1).
abstract Type DeclaringType
Gets the class that declares this member.
Definition: MemberInfo.cs:36
Discovers the attributes of a field and provides access to field metadata.
Definition: FieldInfo.cs:15
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
Definition: BindingFlags.cs:10
Definition: __Canon.cs:3
virtual Type [] GetOptionalCustomModifiers()
Gets an array of types that identify the optional custom modifiers of the field.
Definition: FieldInfo.cs:299
Represents a field using an internal metadata token.
bool IsInitOnly
Gets a value indicating whether the field can only be set in the body of the constructor.
Definition: FieldInfo.cs:144
Represents a type using an internal metadata token.
virtual bool IsGenericType
Gets a value indicating whether the current type is a generic type.
Definition: Type.cs:566
static Binder DefaultBinder
Gets a reference to the default binder, which implements internal rules for selecting the appropriate...
Definition: Type.cs:109
void Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
Provides access to properties and methods exposed by an object.
SecurityAction
Specifies the security actions that can be performed using declarative security.
void GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
Maps a set of names to a corresponding set of dispatch identifiers.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
Describes objects that contain both a managed pointer to a location and a runtime representation of t...
override MemberTypes MemberType
Gets a T:System.Reflection.MemberTypes value indicating that this member is a field.
Definition: FieldInfo.cs:19
static bool operator !=(FieldInfo left, FieldInfo right)
Indicates whether two T:System.Reflection.FieldInfo objects are not equal.
Definition: FieldInfo.cs:267
abstract RuntimeFieldHandle FieldHandle
Gets a RuntimeFieldHandle, which is a handle to the internal metadata representation of a field.
Definition: FieldInfo.cs:25
FieldAttributes
Specifies flags that describe the attributes of a field.
bool IsAssembly
Gets a value indicating whether the potential visibility of this field is described by F:System....
Definition: FieldInfo.cs:92
static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle, RuntimeTypeHandle declaringType)
Gets a T:System.Reflection.FieldInfo for the field represented by the specified handle,...
Definition: FieldInfo.cs:233
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
virtual Type [] GetRequiredCustomModifiers()
Gets an array of types that identify the required custom modifiers of the property.
Definition: FieldInfo.cs:292
new Type GetType()
Provides COM objects with version-independent access to the M:System.Object.GetType method.
abstract string Name
Gets the name of the current member.
Definition: MemberInfo.cs:27
void SetValue(object obj, object value)
Sets the value of the field supported by the given object.
Definition: FieldInfo.cs:368
bool IsFamilyAndAssembly
Gets a value indicating whether the visibility of this field is described by F:System....
Definition: FieldInfo.cs:105
Selects a member from a list of candidates, and performs type conversion from actual argument type to...
Definition: Binder.cs:10
Exposes the public members of the T:System.Reflection.FieldInfo class to unmanaged code.
Definition: _FieldInfo.cs:12
abstract FieldAttributes Attributes
Gets the attributes associated with this field.
Definition: FieldInfo.cs:43
bool IsPublic
Gets a value indicating whether the field is public.
Definition: FieldInfo.cs:53
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
Definition: CultureInfo.cs:120
The exception that is thrown when one of the arguments provided to a method is not valid.
override bool Equals(object obj)
Returns a value that indicates whether this instance is equal to a specified object.
Definition: FieldInfo.cs:277
static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle)
Gets a T:System.Reflection.FieldInfo for the field represented by the specified handle.
Definition: FieldInfo.cs:209
virtual void SetValueDirect(TypedReference obj, object value)
Sets the value of the field supported by the given object.
Definition: FieldInfo.cs:309
bool IsFamilyOrAssembly
Gets a value indicating whether the potential visibility of this field is described by F:System....
Definition: FieldInfo.cs:118
virtual object GetRawConstantValue()
Returns a literal value associated with the field by a compiler.
Definition: FieldInfo.cs:341
virtual object GetValueDirect(TypedReference obj)
Returns the value of a field supported by a given object.
Definition: FieldInfo.cs:321
Specifies that the class can be serialized.
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
MemberTypes
Marks each type of member that is defined as a derived class of T:System.Reflection....
Definition: MemberTypes.cs:9
bool IsPrivate
Gets a value indicating whether the field is private.
Definition: FieldInfo.cs:66
The exception that is thrown when a requested method or operation is not implemented.
bool IsFamily
Gets a value indicating whether the visibility of this field is described by F:System....
Definition: FieldInfo.cs:79
override int GetHashCode()
Returns the hash code for this instance.
Definition: FieldInfo.cs:285