PropertyInfo.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 class PropertyInfo : MemberInfo
  9. {
  10. protected PropertyInfo() { }
  11. public override MemberTypes MemberType => MemberTypes.Property;
  12. public abstract Type PropertyType { get; }
  13. public abstract ParameterInfo[] GetIndexParameters();
  14. public abstract PropertyAttributes Attributes { get; }
  15. public bool IsSpecialName => (Attributes & PropertyAttributes.SpecialName) != 0;
  16. public abstract bool CanRead { get; }
  17. public abstract bool CanWrite { get; }
  18. public MethodInfo[] GetAccessors() => GetAccessors(nonPublic: false);
  19. public abstract MethodInfo[] GetAccessors(bool nonPublic);
  20. public virtual MethodInfo GetMethod => GetGetMethod(nonPublic: true);
  21. public MethodInfo GetGetMethod() => GetGetMethod(nonPublic: false);
  22. public abstract MethodInfo GetGetMethod(bool nonPublic);
  23. public virtual MethodInfo SetMethod => GetSetMethod(nonPublic: true);
  24. public MethodInfo GetSetMethod() => GetSetMethod(nonPublic: false);
  25. public abstract MethodInfo GetSetMethod(bool nonPublic);
  26. public virtual Type[] GetOptionalCustomModifiers() => Array.Empty<Type>();
  27. public virtual Type[] GetRequiredCustomModifiers() => Array.Empty<Type>();
  28. [DebuggerHidden]
  29. [DebuggerStepThrough]
  30. public object GetValue(object obj) => GetValue(obj, index: null);
  31. [DebuggerHidden]
  32. [DebuggerStepThrough]
  33. public virtual object GetValue(object obj, object[] index) => GetValue(obj, BindingFlags.Default, binder: null, index: index, culture: null);
  34. public abstract object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture);
  35. public virtual object GetConstantValue() { throw NotImplemented.ByDesign; }
  36. public virtual object GetRawConstantValue() { throw NotImplemented.ByDesign; }
  37. [DebuggerHidden]
  38. [DebuggerStepThrough]
  39. public void SetValue(object obj, object value) => SetValue(obj, value, index: null);
  40. [DebuggerHidden]
  41. [DebuggerStepThrough]
  42. public virtual void SetValue(object obj, object value, object[] index) => SetValue(obj, value, BindingFlags.Default, binder: null, index: index, culture: null);
  43. public abstract void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture);
  44. public override bool Equals(object obj) => base.Equals(obj);
  45. public override int GetHashCode() => base.GetHashCode();
  46. public static bool operator ==(PropertyInfo left, PropertyInfo right)
  47. {
  48. if (object.ReferenceEquals(left, right))
  49. return true;
  50. if ((object)left == null || (object)right == null)
  51. return false;
  52. return left.Equals(right);
  53. }
  54. public static bool operator !=(PropertyInfo left, PropertyInfo right) => !(left == right);
  55. }
  56. }