Allow at max one Remove operation to fail in tests.
[mono.git] / mcs / class / corlib / System.Reflection.Emit / PropertyBuilder.cs
1
2 //
3 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 // 
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
15 // 
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24
25 //
26 // System.Reflection.Emit/PropertyBuilder.cs
27 //
28 // Author:
29 //   Paolo Molaro (lupus@ximian.com)
30 //
31 // (C) 2001 Ximian, Inc.  http://www.ximian.com
32 //
33
34 using System;
35 using System.Reflection;
36 using System.Reflection.Emit;
37 using System.Globalization;
38 using System.Runtime.CompilerServices;
39 using System.Runtime.InteropServices;
40
41 namespace System.Reflection.Emit {
42         [ComVisible (true)]
43         [ComDefaultInterface (typeof (_PropertyBuilder))]
44         [ClassInterface (ClassInterfaceType.None)]
45         public sealed class PropertyBuilder : PropertyInfo, _PropertyBuilder {
46
47 #pragma warning disable 169, 414
48                 private PropertyAttributes attrs;
49                 private string name;
50                 private Type type;
51                 private Type[] parameters;
52                 private CustomAttributeBuilder[] cattrs;
53                 private object def_value;
54                 private MethodBuilder set_method;
55                 private MethodBuilder get_method;
56                 private int table_idx = 0;
57                 internal TypeBuilder typeb;
58                 private Type[] returnModReq;
59                 private Type[] returnModOpt;
60                 private Type[][] paramModReq;
61                 private Type[][] paramModOpt;
62 #pragma warning restore 169, 414
63                 CallingConventions callingConvention;   // TODO: Implement
64                 
65                 internal PropertyBuilder (TypeBuilder tb, string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnModReq, Type[] returnModOpt, Type[] parameterTypes, Type[][] paramModReq, Type[][] paramModOpt)
66                 {
67                         this.name = name;
68                         this.attrs = attributes;
69                         this.callingConvention = callingConvention;
70                         this.type = returnType;
71                         this.returnModReq = returnModReq;
72                         this.returnModOpt = returnModOpt;
73                         this.paramModReq = paramModReq;
74                         this.paramModOpt = paramModOpt;
75                         if (parameterTypes != null) {
76                                 this.parameters = new Type [parameterTypes.Length];
77                                 System.Array.Copy (parameterTypes, this.parameters, this.parameters.Length);
78                         }
79                         typeb = tb;
80                         table_idx = tb.get_next_table_index (this, 0x17, true);
81                 }
82
83                 public override PropertyAttributes Attributes {
84                         get {return attrs;}
85                 }
86                 public override bool CanRead {
87                         get {return get_method != null;}
88                 }
89                 public override bool CanWrite {
90                         get {return set_method != null;}
91                 }
92                 public override Type DeclaringType {
93                         get {return typeb;}
94                 }
95                 public override string Name {
96                         get {return name;}
97                 }
98                 public PropertyToken PropertyToken {
99                         get {return new PropertyToken ();}
100                 }
101                 public override Type PropertyType {
102                         get {return type;}
103                 }
104                 public override Type ReflectedType {
105                         get {return typeb;}
106                 }
107                 public void AddOtherMethod( MethodBuilder mdBuilder) {
108                 }
109                 public override MethodInfo[] GetAccessors( bool nonPublic) {
110                         return null;
111                 }
112                 public override object[] GetCustomAttributes(bool inherit) {
113                         throw not_supported ();
114                 }
115                 public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
116                         throw not_supported ();
117                 }
118                 public override MethodInfo GetGetMethod( bool nonPublic) {
119                         return get_method;
120                 }
121                 public override ParameterInfo[] GetIndexParameters() {
122                         throw not_supported ();
123                 }
124                 public override MethodInfo GetSetMethod( bool nonPublic) {
125                         return set_method;
126                 }
127                 public override object GetValue(object obj, object[] index) {
128                         return null;
129                 }
130                 public override object GetValue( object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) {
131                         throw not_supported ();
132                 }
133                 public override bool IsDefined( Type attributeType, bool inherit) {
134                         throw not_supported ();
135                 }
136                 public void SetConstant( object defaultValue) {
137                         def_value = defaultValue;
138                 }
139                 public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
140                         string attrname = customBuilder.Ctor.ReflectedType.FullName;
141                         if (attrname == "System.Runtime.CompilerServices.SpecialNameAttribute") {
142                                 attrs |= PropertyAttributes.SpecialName;
143                                 return;
144                         }
145
146                         if (cattrs != null) {
147                                 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
148                                 cattrs.CopyTo (new_array, 0);
149                                 new_array [cattrs.Length] = customBuilder;
150                                 cattrs = new_array;
151                         } else {
152                                 cattrs = new CustomAttributeBuilder [1];
153                                 cattrs [0] = customBuilder;
154                         }
155                 }
156
157                 [ComVisible (true)]
158                 public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
159                         SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
160                 }
161                 public void SetGetMethod( MethodBuilder mdBuilder) {
162                         get_method = mdBuilder;
163                 }
164                 public void SetSetMethod( MethodBuilder mdBuilder) {
165                         set_method = mdBuilder;
166                 }
167                 public override void SetValue( object obj, object value, object[] index) {
168                 }
169                 public override void SetValue( object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) {
170                 }
171
172                 public override Module Module {
173                         get {
174                                 return base.Module;
175                         }
176                 }
177
178                 void _PropertyBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
179                 {
180                         throw new NotImplementedException ();
181                 }
182
183                 void _PropertyBuilder.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
184                 {
185                         throw new NotImplementedException ();
186                 }
187
188                 void _PropertyBuilder.GetTypeInfoCount (out uint pcTInfo)
189                 {
190                         throw new NotImplementedException ();
191                 }
192
193                 void _PropertyBuilder.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
194                 {
195                         throw new NotImplementedException ();
196                 }
197
198                 private Exception not_supported ()
199                 {
200                         return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
201                 }
202         }
203 }
204