2 // System.Reflection.Emit.GenericTypeParameterBuilder
4 // Martin Baulig (martin@ximian.com)
6 // (C) 2004 Novell, Inc.
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Reflection;
34 using System.Reflection.Emit;
35 using System.Collections;
36 using System.Runtime.CompilerServices;
37 using System.Runtime.InteropServices;
38 using System.Globalization;
39 using System.Runtime.Serialization;
41 namespace System.Reflection.Emit
44 [StructLayout (LayoutKind.Sequential)]
45 public sealed class GenericTypeParameterBuilder :
52 #region Sync with reflection.h
53 private TypeBuilder tbuilder;
54 private MethodBuilder mbuilder;
57 private Type base_type;
58 #pragma warning disable 414
59 private Type[] iface_constraints;
60 private CustomAttributeBuilder[] cattrs;
61 private GenericParameterAttributes attrs;
62 #pragma warning restore
65 public void SetBaseTypeConstraint (Type baseTypeConstraint)
67 this.base_type = baseTypeConstraint ?? typeof (object);
71 public void SetInterfaceConstraints (params Type[] interfaceConstraints)
73 this.iface_constraints = interfaceConstraints;
76 public void SetGenericParameterAttributes (GenericParameterAttributes genericParameterAttributes)
78 this.attrs = genericParameterAttributes;
81 internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
82 MethodBuilder mbuilder,
83 string name, int index)
85 this.tbuilder = tbuilder;
86 this.mbuilder = mbuilder;
93 internal override Type InternalResolve ()
95 return tbuilder.InternalResolve ().GetGenericArguments () [index];
98 [MethodImplAttribute(MethodImplOptions.InternalCall)]
99 private extern void initialize ();
102 public override bool IsSubclassOf (Type c)
104 throw not_supported ();
107 protected override TypeAttributes GetAttributeFlagsImpl ()
110 return TypeAttributes.Public;
112 throw not_supported ();
116 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
118 CallingConventions callConvention,
120 ParameterModifier[] modifiers)
122 throw not_supported ();
126 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
128 throw not_supported ();
131 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
133 throw not_supported ();
136 public override EventInfo[] GetEvents ()
138 throw not_supported ();
141 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
143 throw not_supported ();
146 public override FieldInfo GetField (string name, BindingFlags bindingAttr)
148 throw not_supported ();
151 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
153 throw not_supported ();
156 public override Type GetInterface (string name, bool ignoreCase)
158 throw not_supported ();
161 public override Type[] GetInterfaces ()
163 throw not_supported ();
166 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
168 throw not_supported ();
171 public override MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
173 throw not_supported ();
176 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
178 throw not_supported ();
181 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
183 CallingConventions callConvention,
184 Type[] types, ParameterModifier[] modifiers)
186 throw not_supported ();
189 public override Type GetNestedType (string name, BindingFlags bindingAttr)
191 throw not_supported ();
194 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
196 throw not_supported ();
199 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
201 throw not_supported ();
204 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
205 Binder binder, Type returnType,
207 ParameterModifier[] modifiers)
209 throw not_supported ();
212 protected override bool HasElementTypeImpl ()
217 public override bool IsAssignableFrom (Type c)
219 throw not_supported ();
222 public override bool IsInstanceOfType (object o)
224 throw not_supported ();
227 protected override bool IsArrayImpl ()
232 protected override bool IsByRefImpl ()
237 protected override bool IsCOMObjectImpl ()
242 protected override bool IsPointerImpl ()
247 protected override bool IsPrimitiveImpl ()
252 protected override bool IsValueTypeImpl ()
254 return base_type != null ? base_type.IsValueType : false;
257 public override object InvokeMember (string name, BindingFlags invokeAttr,
258 Binder binder, object target, object[] args,
259 ParameterModifier[] modifiers,
260 CultureInfo culture, string[] namedParameters)
262 throw not_supported ();
265 public override Type GetElementType ()
267 throw not_supported ();
270 public override Type UnderlyingSystemType {
276 public override Assembly Assembly {
277 get { return tbuilder.Assembly; }
280 public override string AssemblyQualifiedName {
284 public override Type BaseType {
285 get { return base_type; }
288 public override string FullName {
292 public override Guid GUID {
293 get { throw not_supported (); }
296 public override bool IsDefined (Type attributeType, bool inherit)
298 throw not_supported ();
301 public override object[] GetCustomAttributes (bool inherit)
303 throw not_supported ();
306 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
308 throw not_supported ();
312 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
314 throw not_supported ();
317 public override string Name {
321 public override string Namespace {
325 public override Module Module {
326 get { return tbuilder.Module; }
329 public override Type DeclaringType {
330 get { return mbuilder != null ? mbuilder.DeclaringType : tbuilder; }
333 public override Type ReflectedType {
334 get { return DeclaringType; }
337 public override RuntimeTypeHandle TypeHandle {
338 get { throw not_supported (); }
341 public override Type[] GetGenericArguments ()
343 throw new InvalidOperationException ();
346 public override Type GetGenericTypeDefinition ()
348 throw new InvalidOperationException ();
351 public override bool ContainsGenericParameters {
355 public override bool IsGenericParameter {
359 public override bool IsGenericType {
360 get { return false; }
363 public override bool IsGenericTypeDefinition {
364 get { return false; }
367 public override GenericParameterAttributes GenericParameterAttributes {
369 throw new NotSupportedException ();
373 public override int GenericParameterPosition {
374 get { return index; }
377 public override Type[] GetGenericParameterConstraints ()
379 throw new InvalidOperationException ();
382 public override MethodBase DeclaringMethod {
383 get { return mbuilder; }
386 public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
388 if (customBuilder == null)
389 throw new ArgumentNullException ("customBuilder");
391 if (cattrs != null) {
392 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
393 cattrs.CopyTo (new_array, 0);
394 new_array [cattrs.Length] = customBuilder;
397 cattrs = new CustomAttributeBuilder [1];
398 cattrs [0] = customBuilder;
402 [MonoTODO ("unverified implementation")]
403 public void SetCustomAttribute (ConstructorInfo con, byte [] binaryAttribute)
405 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
408 private Exception not_supported ()
410 return new NotSupportedException ();
413 public override string ToString ()
419 public override bool Equals (object o)
421 return base.Equals (o);
425 public override int GetHashCode ()
427 return base.GetHashCode ();
430 public override Type MakeArrayType ()
432 return new ArrayType (this, 0);
435 public override Type MakeArrayType (int rank)
438 throw new IndexOutOfRangeException ();
439 return new ArrayType (this, rank);
442 public override Type MakeByRefType ()
444 return new ByRefType (this);
448 public override Type MakeGenericType (params Type [] typeArguments)
450 return base.MakeGenericType (typeArguments);
453 public override Type MakePointerType ()
455 return new PointerType (this);
458 internal override bool IsUserType {