FieldInfo.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Diagnostics;
  5. using System.Globalization;
  6. namespace System.Reflection
  7. {
  8. public abstract partial class FieldInfo : MemberInfo
  9. {
  10. protected FieldInfo() { }
  11. public override MemberTypes MemberType => MemberTypes.Field;
  12. public abstract FieldAttributes Attributes { get; }
  13. public abstract Type FieldType { get; }
  14. public bool IsInitOnly => (Attributes & FieldAttributes.InitOnly) != 0;
  15. public bool IsLiteral => (Attributes & FieldAttributes.Literal) != 0;
  16. public bool IsNotSerialized => (Attributes & FieldAttributes.NotSerialized) != 0;
  17. public bool IsPinvokeImpl => (Attributes & FieldAttributes.PinvokeImpl) != 0;
  18. public bool IsSpecialName => (Attributes & FieldAttributes.SpecialName) != 0;
  19. public bool IsStatic => (Attributes & FieldAttributes.Static) != 0;
  20. public bool IsAssembly => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly;
  21. public bool IsFamily => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family;
  22. public bool IsFamilyAndAssembly => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem;
  23. public bool IsFamilyOrAssembly => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem;
  24. public bool IsPrivate => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private;
  25. public bool IsPublic => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public;
  26. public virtual bool IsSecurityCritical => true;
  27. public virtual bool IsSecuritySafeCritical => false;
  28. public virtual bool IsSecurityTransparent => false;
  29. public abstract RuntimeFieldHandle FieldHandle { get; }
  30. public override bool Equals(object obj) => base.Equals(obj);
  31. public override int GetHashCode() => base.GetHashCode();
  32. public static bool operator ==(FieldInfo left, FieldInfo right)
  33. {
  34. if (object.ReferenceEquals(left, right))
  35. return true;
  36. if ((object)left == null || (object)right == null)
  37. return false;
  38. return left.Equals(right);
  39. }
  40. public static bool operator !=(FieldInfo left, FieldInfo right) => !(left == right);
  41. public abstract object GetValue(object obj);
  42. [DebuggerHidden]
  43. [DebuggerStepThrough]
  44. public void SetValue(object obj, object value) => SetValue(obj, value, BindingFlags.Default, Type.DefaultBinder, null);
  45. public abstract void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture);
  46. [CLSCompliant(false)]
  47. public virtual void SetValueDirect(TypedReference obj, object value) { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); }
  48. [CLSCompliant(false)]
  49. public virtual object GetValueDirect(TypedReference obj) { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); }
  50. public virtual object GetRawConstantValue() { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); }
  51. public virtual Type[] GetOptionalCustomModifiers() { throw NotImplemented.ByDesign; }
  52. public virtual Type[] GetRequiredCustomModifiers() { throw NotImplemented.ByDesign; }
  53. }
  54. }