Prevent race conditions for this cached variable, by using a temporary variable,...
[mono.git] / mcs / class / IKVM.Reflection / PropertyInfo.cs
1 /*
2   Copyright (C) 2009 Jeroen Frijters
3
4   This software is provided 'as-is', without any express or implied
5   warranty.  In no event will the authors be held liable for any damages
6   arising from the use of this software.
7
8   Permission is granted to anyone to use this software for any purpose,
9   including commercial applications, and to alter it and redistribute it
10   freely, subject to the following restrictions:
11
12   1. The origin of this software must not be misrepresented; you must not
13      claim that you wrote the original software. If you use this software
14      in a product, an acknowledgment in the product documentation would be
15      appreciated but is not required.
16   2. Altered source versions must be plainly marked as such, and must not be
17      misrepresented as being the original software.
18   3. This notice may not be removed or altered from any source distribution.
19
20   Jeroen Frijters
21   jeroen@frijters.net
22   
23 */
24 using System;
25
26 namespace IKVM.Reflection
27 {
28         public abstract class PropertyInfo : MemberInfo
29         {
30                 // prevent external subclasses
31                 internal PropertyInfo()
32                 {
33                 }
34
35                 public sealed override MemberTypes MemberType
36                 {
37                         get { return MemberTypes.Property; }
38                 }
39
40                 public abstract PropertyAttributes Attributes { get; }
41                 public abstract bool CanRead { get; }
42                 public abstract bool CanWrite { get; }
43                 public abstract MethodInfo GetGetMethod(bool nonPublic);
44                 public abstract MethodInfo GetSetMethod(bool nonPublic);
45                 public abstract MethodInfo[] GetAccessors(bool nonPublic);
46                 public abstract object GetRawConstantValue();
47                 internal abstract bool IsPublic { get; }
48                 internal abstract bool IsStatic { get; }
49                 internal abstract PropertySignature PropertySignature { get; }
50
51                 private sealed class ParameterInfoImpl : ParameterInfo
52                 {
53                         private readonly PropertyInfo property;
54                         private readonly int parameter;
55
56                         internal ParameterInfoImpl(PropertyInfo property, int parameter)
57                         {
58                                 this.property = property;
59                                 this.parameter = parameter;
60                         }
61
62                         public override string Name
63                         {
64                                 get { return null; }
65                         }
66
67                         public override Type ParameterType
68                         {
69                                 get { return property.PropertySignature.GetParameter(parameter); }
70                         }
71
72                         public override ParameterAttributes Attributes
73                         {
74                                 get { return ParameterAttributes.None; }
75                         }
76
77                         public override int Position
78                         {
79                                 get { return parameter; }
80                         }
81
82                         public override object RawDefaultValue
83                         {
84                                 get { throw new InvalidOperationException(); }
85                         }
86
87                         public override CustomModifiers __GetCustomModifiers()
88                         {
89                                 return property.PropertySignature.GetParameterCustomModifiers(parameter);
90                         }
91
92                         public override MemberInfo Member
93                         {
94                                 get { return property; }
95                         }
96
97                         public override int MetadataToken
98                         {
99                                 get { return 0x08000000; }
100                         }
101
102                         internal override Module Module
103                         {
104                                 get { return property.Module; }
105                         }
106                 }
107
108                 public ParameterInfo[] GetIndexParameters()
109                 {
110                         ParameterInfo[] parameters = new ParameterInfo[this.PropertySignature.ParameterCount];
111                         for (int i = 0; i < parameters.Length; i++)
112                         {
113                                 parameters[i] = new ParameterInfoImpl(this, i);
114                         }
115                         return parameters;
116                 }
117
118                 public Type PropertyType
119                 {
120                         get { return this.PropertySignature.PropertyType; }
121                 }
122
123                 public CustomModifiers __GetCustomModifiers()
124                 {
125                         return this.PropertySignature.GetCustomModifiers();
126                 }
127
128                 public Type[] GetRequiredCustomModifiers()
129                 {
130                         return __GetCustomModifiers().GetRequired();
131                 }
132
133                 public Type[] GetOptionalCustomModifiers()
134                 {
135                         return __GetCustomModifiers().GetOptional();
136                 }
137
138                 public bool IsSpecialName
139                 {
140                         get { return (Attributes & PropertyAttributes.SpecialName) != 0; }
141                 }
142
143                 public MethodInfo GetGetMethod()
144                 {
145                         return GetGetMethod(false);
146                 }
147
148                 public MethodInfo GetSetMethod()
149                 {
150                         return GetSetMethod(false);
151                 }
152
153                 public MethodInfo[] GetAccessors()
154                 {
155                         return GetAccessors(false);
156                 }
157
158                 public CallingConventions __CallingConvention
159                 {
160                         get { return this.PropertySignature.CallingConvention; }
161                 }
162
163                 internal virtual PropertyInfo BindTypeParameters(Type type)
164                 {
165                         return new GenericPropertyInfo(this.DeclaringType.BindTypeParameters(type), this);
166                 }
167
168                 public override string ToString()
169                 {
170                         return this.DeclaringType.ToString() + " " + Name;
171                 }
172         }
173 }