Merge pull request #585 from mk8/master
[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 #if MOBILE
42         public abstract class PropertyInfo : MemberInfo {
43 #else
44         public abstract class PropertyInfo : MemberInfo, _PropertyInfo {
45 #endif
46                 public abstract PropertyAttributes Attributes { get; }
47                 public abstract bool CanRead { get; }
48                 public abstract bool CanWrite { get; }
49                 
50 #if NET_4_5
51                 public virtual MethodInfo GetMethod {
52                         get { return GetGetMethod(true); }
53                 }
54
55                 public virtual MethodInfo SetMethod {
56                         get { return GetSetMethod(true); }
57                 }
58 #endif
59
60                 public bool IsSpecialName {
61                         get {return (Attributes & PropertyAttributes.SpecialName) != 0;}
62                 }
63
64                 public override MemberTypes MemberType {
65                         get {return MemberTypes.Property;}
66                 }
67                 public abstract Type PropertyType { get; }
68         
69                 protected PropertyInfo () { }
70
71                 public MethodInfo[] GetAccessors ()
72                 {
73                         return GetAccessors (false);
74                 }
75                 
76                 public abstract MethodInfo[] GetAccessors (bool nonPublic);
77
78                 public MethodInfo GetGetMethod()
79                 {
80                         return GetGetMethod (false);
81                 }
82                 public abstract MethodInfo GetGetMethod(bool nonPublic);
83                 
84                 public abstract ParameterInfo[] GetIndexParameters();
85
86                 public MethodInfo GetSetMethod()
87                 {
88                         return GetSetMethod (false);
89                 }
90                 
91                 public abstract MethodInfo GetSetMethod (bool nonPublic);
92                 
93                 [DebuggerHidden]
94                 [DebuggerStepThrough]
95                 public virtual object GetValue (object obj, object[] index)
96                 {
97                         return GetValue(obj, BindingFlags.Default, null, index, null);
98                 }
99
100 #if NET_4_5
101                 [DebuggerHidden]
102                 [DebuggerStepThrough]
103                 public object GetValue (object obj)
104                 {
105                         return GetValue(obj, BindingFlags.Default, null, null, null);
106                 }
107 #endif
108
109                 public abstract object GetValue (object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture);
110                 
111                 [DebuggerHidden]
112                 [DebuggerStepThrough]
113                 public virtual void SetValue (object obj, object value, object[] index)
114                 {
115                         SetValue (obj, value, BindingFlags.Default, null, index, null);
116                 }
117
118 #if NET_4_5
119                 [DebuggerHidden]
120                 [DebuggerStepThrough]
121                 public void SetValue (object obj, object value)
122                 {
123                         SetValue (obj, value, BindingFlags.Default, null, null, null);
124                 }
125 #endif
126
127                 public abstract void SetValue (object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture);
128
129                 public virtual Type[] GetOptionalCustomModifiers () {
130                         return Type.EmptyTypes;
131                 }
132
133                 public virtual Type[] GetRequiredCustomModifiers () {
134                         return Type.EmptyTypes;
135                 }
136
137                 static NotImplementedException CreateNIE ()
138                 {
139                         return new NotImplementedException ();
140                 }
141
142                 public virtual object GetConstantValue () {
143                         throw CreateNIE ();
144                 }
145
146                 public virtual object GetRawConstantValue() {
147                         throw CreateNIE ();
148                 }
149
150 #if NET_4_0
151                 public override bool Equals (object obj)
152                 {
153                         return obj == (object) this;
154                 }
155
156                 public override int GetHashCode ()
157                 {
158                         return base.GetHashCode ();
159                 }
160
161                 public static bool operator == (PropertyInfo left, PropertyInfo right)
162                 {
163                         if ((object)left == (object)right)
164                                 return true;
165                         if ((object)left == null ^ (object)right == null)
166                                 return false;
167                         return left.Equals (right);
168                 }
169
170                 public static bool operator != (PropertyInfo left, PropertyInfo right)
171                 {
172                         if ((object)left == (object)right)
173                                 return false;
174                         if ((object)left == null ^ (object)right == null)
175                                 return true;
176                         return !left.Equals (right);
177                 }
178 #endif
179
180 #if !MOBILE
181                 void _PropertyInfo.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
182                 {
183                         throw new NotImplementedException ();
184                 }
185
186                 Type _PropertyInfo.GetType ()
187                 {
188                         // Required or object::GetType becomes virtual final
189                         return base.GetType ();
190                 }               
191
192                 void _PropertyInfo.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
193                 {
194                         throw new NotImplementedException ();
195                 }
196
197                 void _PropertyInfo.GetTypeInfoCount (out uint pcTInfo)
198                 {
199                         throw new NotImplementedException ();
200                 }
201
202                 void _PropertyInfo.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
203                 {
204                         throw new NotImplementedException ();
205                 }
206 #endif
207         }
208 }