summaryrefslogtreecommitdiff
path: root/src/mscorlib/shared/System/Reflection/PropertyInfo.cs
blob: ff8a02e96d346e3383783099cf849b7fe7641d73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Globalization;

namespace System.Reflection
{
    public abstract class PropertyInfo : MemberInfo
    {
        protected PropertyInfo() { }

        public override MemberTypes MemberType => MemberTypes.Property;

        public abstract Type PropertyType { get; }
        public abstract ParameterInfo[] GetIndexParameters();

        public abstract PropertyAttributes Attributes { get; }
        public bool IsSpecialName => (Attributes & PropertyAttributes.SpecialName) != 0;

        public abstract bool CanRead { get; }
        public abstract bool CanWrite { get; }

        public MethodInfo[] GetAccessors() => GetAccessors(nonPublic: false);
        public abstract MethodInfo[] GetAccessors(bool nonPublic);

        public virtual MethodInfo GetMethod => GetGetMethod(nonPublic: true);
        public MethodInfo GetGetMethod() => GetGetMethod(nonPublic: false);
        public abstract MethodInfo GetGetMethod(bool nonPublic);

        public virtual MethodInfo SetMethod => GetSetMethod(nonPublic: true);
        public MethodInfo GetSetMethod() => GetSetMethod(nonPublic: false);
        public abstract MethodInfo GetSetMethod(bool nonPublic);

        public virtual Type[] GetOptionalCustomModifiers() => Array.Empty<Type>();
        public virtual Type[] GetRequiredCustomModifiers() => Array.Empty<Type>();

        [DebuggerHidden]
        [DebuggerStepThrough]
        public object GetValue(object obj) => GetValue(obj, index: null);
        [DebuggerHidden]
        [DebuggerStepThrough]
        public virtual object GetValue(object obj, object[] index) => GetValue(obj, BindingFlags.Default, binder: null, index: index, culture: null);
        public abstract object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture);

        public virtual object GetConstantValue() { throw NotImplemented.ByDesign; }
        public virtual object GetRawConstantValue() { throw NotImplemented.ByDesign; }

        [DebuggerHidden]
        [DebuggerStepThrough]
        public void SetValue(object obj, object value) => SetValue(obj, value, index: null);
        [DebuggerHidden]
        [DebuggerStepThrough]
        public virtual void SetValue(object obj, object value, object[] index) => SetValue(obj, value, BindingFlags.Default, binder: null, index: index, culture: null);
        public abstract void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture);

        public override bool Equals(object obj) => base.Equals(obj);
        public override int GetHashCode() => base.GetHashCode();

        public static bool operator ==(PropertyInfo left, PropertyInfo right)
        {
            if (object.ReferenceEquals(left, right))
                return true;

            if ((object)left == null || (object)right == null)
                return false;

            return left.Equals(right);
        }

        public static bool operator !=(PropertyInfo left, PropertyInfo right) => !(left == right);
    }
}