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.
32 using System.Reflection;
33 using System.Reflection.Emit;
34 using System.Collections;
35 using System.Runtime.CompilerServices;
36 using System.Runtime.InteropServices;
37 using System.Globalization;
38 using System.Runtime.Serialization;
40 namespace System.Reflection.Emit
43 public sealed class GenericTypeParameterBuilder : Type
45 #region Sync with reflection.h
46 private TypeBuilder tbuilder;
47 private MethodBuilder mbuilder;
50 private Type base_type;
51 private Type[] iface_constraints;
52 private CustomAttributeBuilder[] cattrs;
53 private GenericParameterAttributes attrs;
56 public void SetBaseTypeConstraint (Type baseTypeConstraint)
58 this.base_type = baseTypeConstraint ?? typeof (object);
62 public void SetInterfaceConstraints (params Type[] interfaceConstraints)
64 this.iface_constraints = interfaceConstraints;
67 public void SetGenericParameterAttributes (GenericParameterAttributes genericParameterAttributes)
69 this.attrs = genericParameterAttributes;
72 internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
73 MethodBuilder mbuilder,
74 string name, int index)
76 this.tbuilder = tbuilder;
77 this.mbuilder = mbuilder;
85 internal override bool IsCompilerContext {
87 return tbuilder.IsCompilerContext;
91 internal override Type InternalResolve ()
93 return tbuilder.InternalResolve ().GetGenericArguments () [index];
96 [MethodImplAttribute(MethodImplOptions.InternalCall)]
97 private extern void initialize ();
100 public override bool IsSubclassOf (Type c)
102 if (!IsCompilerContext)
103 throw not_supported ();
104 if (BaseType == null)
107 return BaseType == c || BaseType.IsSubclassOf (c);
110 protected override TypeAttributes GetAttributeFlagsImpl ()
113 return TypeAttributes.Public;
115 if (IsCompilerContext)
116 return TypeAttributes.Public;
117 throw not_supported ();
121 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
123 CallingConventions callConvention,
125 ParameterModifier[] modifiers)
127 throw not_supported ();
131 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
133 throw not_supported ();
136 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
138 throw not_supported ();
141 public override EventInfo[] GetEvents ()
143 throw not_supported ();
146 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
148 throw not_supported ();
151 public override FieldInfo GetField (string name, BindingFlags bindingAttr)
153 throw not_supported ();
156 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
158 throw not_supported ();
161 public override Type GetInterface (string name, bool ignoreCase)
163 throw not_supported ();
166 public override Type[] GetInterfaces ()
168 throw not_supported ();
171 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
173 throw not_supported ();
176 public override MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
178 throw not_supported ();
181 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
183 throw not_supported ();
186 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
188 CallingConventions callConvention,
189 Type[] types, ParameterModifier[] modifiers)
191 throw not_supported ();
194 public override Type GetNestedType (string name, BindingFlags bindingAttr)
196 throw not_supported ();
199 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
201 throw not_supported ();
204 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
206 throw not_supported ();
209 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
210 Binder binder, Type returnType,
212 ParameterModifier[] modifiers)
214 throw not_supported ();
217 protected override bool HasElementTypeImpl ()
222 public override bool IsAssignableFrom (Type c)
224 throw not_supported ();
227 public override bool IsInstanceOfType (object o)
229 throw not_supported ();
232 protected override bool IsArrayImpl ()
237 protected override bool IsByRefImpl ()
242 protected override bool IsCOMObjectImpl ()
247 protected override bool IsPointerImpl ()
252 protected override bool IsPrimitiveImpl ()
257 protected override bool IsValueTypeImpl ()
259 return base_type != null ? base_type.IsValueType : false;
262 public override object InvokeMember (string name, BindingFlags invokeAttr,
263 Binder binder, object target, object[] args,
264 ParameterModifier[] modifiers,
265 CultureInfo culture, string[] namedParameters)
267 throw not_supported ();
270 public override Type GetElementType ()
272 throw not_supported ();
275 public override Type UnderlyingSystemType {
281 public override Assembly Assembly {
282 get { return tbuilder.Assembly; }
285 public override string AssemblyQualifiedName {
289 public override Type BaseType {
290 get { return base_type; }
293 public override string FullName {
297 public override Guid GUID {
298 get { throw not_supported (); }
301 public override bool IsDefined (Type attributeType, bool inherit)
303 throw not_supported ();
306 public override object[] GetCustomAttributes (bool inherit)
308 throw not_supported ();
311 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
313 throw not_supported ();
317 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
319 throw not_supported ();
322 public override string Name {
326 public override string Namespace {
330 public override Module Module {
331 get { return tbuilder.Module; }
334 public override Type DeclaringType {
335 get { return mbuilder != null ? mbuilder.DeclaringType : tbuilder; }
338 public override Type ReflectedType {
339 get { return DeclaringType; }
342 public override RuntimeTypeHandle TypeHandle {
343 get { throw not_supported (); }
346 public override Type[] GetGenericArguments ()
348 throw new InvalidOperationException ();
351 public override Type GetGenericTypeDefinition ()
353 throw new InvalidOperationException ();
356 public override bool ContainsGenericParameters {
360 public override bool IsGenericParameter {
364 public override bool IsGenericType {
365 get { return false; }
368 public override bool IsGenericTypeDefinition {
369 get { return false; }
372 public override GenericParameterAttributes GenericParameterAttributes {
374 if (IsCompilerContext)
376 throw new NotSupportedException ();
380 public override int GenericParameterPosition {
381 get { return index; }
384 public override Type[] GetGenericParameterConstraints ()
386 if (!IsCompilerContext)
387 throw new InvalidOperationException ();
388 if (base_type == null) {
389 if (iface_constraints != null)
390 return iface_constraints;
392 return Type.EmptyTypes;
395 if (iface_constraints == null)
396 return new Type[] { base_type };
398 Type[] ret = new Type [iface_constraints.Length + 1];
400 iface_constraints.CopyTo (ret, 1);
404 public override MethodBase DeclaringMethod {
405 get { return mbuilder; }
408 public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
410 if (customBuilder == null)
411 throw new ArgumentNullException ("customBuilder");
413 if (cattrs != null) {
414 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
415 cattrs.CopyTo (new_array, 0);
416 new_array [cattrs.Length] = customBuilder;
419 cattrs = new CustomAttributeBuilder [1];
420 cattrs [0] = customBuilder;
424 [MonoTODO ("unverified implementation")]
425 public void SetCustomAttribute (ConstructorInfo con, byte [] binaryAttribute)
427 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
430 private Exception not_supported ()
432 return new NotSupportedException ();
435 public override string ToString ()
441 public override bool Equals (object o)
443 return base.Equals (o);
447 public override int GetHashCode ()
449 return base.GetHashCode ();
452 public override Type MakeArrayType ()
454 return new ArrayType (this, 0);
457 public override Type MakeArrayType (int rank)
460 throw new IndexOutOfRangeException ();
461 return new ArrayType (this, rank);
464 public override Type MakeByRefType ()
466 return new ByRefType (this);
470 public override Type MakeGenericType (params Type [] typeArguments)
472 return base.MakeGenericType (typeArguments);
475 public override Type MakePointerType ()
477 return new PointerType (this);