Merge pull request #571 from igotti-google/jt2
[mono.git] / mcs / class / corlib / System.Reflection / PropertyInfo.cs
1 //
2 // System.Reflection/PropertyInfo.cs
3 //
4 // Author:
5 //   Paolo Molaro (lupus@ximian.com)
6 //
7 // (C) 2001 Ximian, Inc.  http://www.ximian.com
8 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System.Diagnostics;
31 using System.Globalization;
32 using System.Runtime.InteropServices;
33 using System.Runtime.CompilerServices;
34
35 namespace System.Reflection {
36
37         [ComVisible (true)]
38         [ComDefaultInterfaceAttribute (typeof (_PropertyInfo))]
39         [Serializable]
40         [ClassInterface(ClassInterfaceType.None)]
41         public abstract class PropertyInfo : MemberInfo, _PropertyInfo {
42
43                 public abstract PropertyAttributes Attributes { get; }
44                 public abstract bool CanRead { get; }
45                 public abstract bool CanWrite { get; }
46                 
47 #if NET_4_5
48                 public virtual MethodInfo GetMethod {
49                         get { return GetGetMethod(true); }
50                 }
51
52                 public virtual MethodInfo SetMethod {
53                         get { return GetSetMethod(true); }
54                 }
55 #endif
56
57                 public bool IsSpecialName {
58                         get {return (Attributes & PropertyAttributes.SpecialName) != 0;}
59                 }
60
61                 public override MemberTypes MemberType {
62                         get {return MemberTypes.Property;}
63                 }
64                 public abstract Type PropertyType { get; }
65         
66                 protected PropertyInfo () { }
67
68                 public MethodInfo[] GetAccessors ()
69                 {
70                         return GetAccessors (false);
71                 }
72                 
73                 public abstract MethodInfo[] GetAccessors (bool nonPublic);
74
75                 public MethodInfo GetGetMethod()
76                 {
77                         return GetGetMethod (false);
78                 }
79                 public abstract MethodInfo GetGetMethod(bool nonPublic);
80                 
81                 public abstract ParameterInfo[] GetIndexParameters();
82
83                 public MethodInfo GetSetMethod()
84                 {
85                         return GetSetMethod (false);
86                 }
87                 
88                 public abstract MethodInfo GetSetMethod (bool nonPublic);
89                 
90                 [DebuggerHidden]
91                 [DebuggerStepThrough]
92                 public virtual object GetValue (object obj, object[] index)
93                 {
94                         return GetValue(obj, BindingFlags.Default, null, index, null);
95                 }
96
97 #if NET_4_5
98                 [DebuggerHidden]
99                 [DebuggerStepThrough]
100                 public object GetValue (object obj)
101                 {
102                         return GetValue(obj, BindingFlags.Default, null, null, null);
103                 }
104 #endif
105
106                 public abstract object GetValue (object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture);
107                 
108                 [DebuggerHidden]
109                 [DebuggerStepThrough]
110                 public virtual void SetValue (object obj, object value, object[] index)
111                 {
112                         SetValue (obj, value, BindingFlags.Default, null, index, null);
113                 }
114
115 #if NET_4_5
116                 [DebuggerHidden]
117                 [DebuggerStepThrough]
118                 public void SetValue (object obj, object value)
119                 {
120                         SetValue (obj, value, BindingFlags.Default, null, null, null);
121                 }
122 #endif
123
124                 public abstract void SetValue (object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture);
125
126                 public virtual Type[] GetOptionalCustomModifiers () {
127                         return Type.EmptyTypes;
128                 }
129
130                 public virtual Type[] GetRequiredCustomModifiers () {
131                         return Type.EmptyTypes;
132                 }
133
134                 static NotImplementedException CreateNIE ()
135                 {
136                         return new NotImplementedException ();
137                 }
138
139                 public virtual object GetConstantValue () {
140                         throw CreateNIE ();
141                 }
142
143                 public virtual object GetRawConstantValue() {
144                         throw CreateNIE ();
145                 }
146
147 #if NET_4_0
148                 public override bool Equals (object obj)
149                 {
150                         return obj == (object) this;
151                 }
152
153                 public override int GetHashCode ()
154                 {
155                         return base.GetHashCode ();
156                 }
157
158                 public static bool operator == (PropertyInfo left, PropertyInfo right)
159                 {
160                         if ((object)left == (object)right)
161                                 return true;
162                         if ((object)left == null ^ (object)right == null)
163                                 return false;
164                         return left.Equals (right);
165                 }
166
167                 public static bool operator != (PropertyInfo left, PropertyInfo right)
168                 {
169                         if ((object)left == (object)right)
170                                 return false;
171                         if ((object)left == null ^ (object)right == null)
172                                 return true;
173                         return !left.Equals (right);
174                 }
175 #endif
176
177                 void _PropertyInfo.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
178                 {
179                         throw new NotImplementedException ();
180                 }
181
182                 Type _PropertyInfo.GetType ()
183                 {
184                         // Required or object::GetType becomes virtual final
185                         return base.GetType ();
186                 }               
187
188                 void _PropertyInfo.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
189                 {
190                         throw new NotImplementedException ();
191                 }
192
193                 void _PropertyInfo.GetTypeInfoCount (out uint pcTInfo)
194                 {
195                         throw new NotImplementedException ();
196                 }
197
198                 void _PropertyInfo.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
199                 {
200                         throw new NotImplementedException ();
201                 }
202         }
203 }