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 :
48 #region Sync with reflection.h
49 private TypeBuilder tbuilder;
50 private MethodBuilder mbuilder;
53 private Type base_type;
54 #pragma warning disable 414
55 private Type[] iface_constraints;
56 private CustomAttributeBuilder[] cattrs;
57 private GenericParameterAttributes attrs;
58 #pragma warning restore
61 public void SetBaseTypeConstraint (Type baseTypeConstraint)
63 this.base_type = baseTypeConstraint ?? typeof (object);
67 public void SetInterfaceConstraints (params Type[] interfaceConstraints)
69 this.iface_constraints = interfaceConstraints;
72 public void SetGenericParameterAttributes (GenericParameterAttributes genericParameterAttributes)
74 this.attrs = genericParameterAttributes;
77 internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
78 MethodBuilder mbuilder,
79 string name, int index)
81 this.tbuilder = tbuilder;
82 this.mbuilder = mbuilder;
89 internal override Type InternalResolve ()
92 return MethodBase.GetMethodFromHandle (mbuilder.MethodHandleInternal).GetGenericArguments () [index];
93 return tbuilder.InternalResolve ().GetGenericArguments () [index];
96 internal override Type RuntimeResolve ()
99 return MethodBase.GetMethodFromHandle (mbuilder.MethodHandleInternal, mbuilder.TypeBuilder.RuntimeResolve ().TypeHandle).GetGenericArguments () [index];
100 return tbuilder.RuntimeResolve ().GetGenericArguments () [index];
103 [MethodImplAttribute(MethodImplOptions.InternalCall)]
104 private extern void initialize ();
107 public override bool IsSubclassOf (Type c)
109 throw not_supported ();
112 protected override TypeAttributes GetAttributeFlagsImpl ()
114 return TypeAttributes.Public;
117 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
119 CallingConventions callConvention,
121 ParameterModifier[] modifiers)
123 throw not_supported ();
127 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
129 throw not_supported ();
132 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
134 throw not_supported ();
137 public override EventInfo[] GetEvents ()
139 throw not_supported ();
142 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
144 throw not_supported ();
147 public override FieldInfo GetField (string name, BindingFlags bindingAttr)
149 throw not_supported ();
152 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
154 throw not_supported ();
157 public override Type GetInterface (string name, bool ignoreCase)
159 throw not_supported ();
162 public override Type[] GetInterfaces ()
164 throw not_supported ();
167 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
169 throw not_supported ();
172 public override MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
174 throw not_supported ();
177 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
179 throw not_supported ();
182 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
184 CallingConventions callConvention,
185 Type[] types, ParameterModifier[] modifiers)
187 throw not_supported ();
190 public override Type GetNestedType (string name, BindingFlags bindingAttr)
192 throw not_supported ();
195 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
197 throw not_supported ();
200 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
202 throw not_supported ();
205 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
206 Binder binder, Type returnType,
208 ParameterModifier[] modifiers)
210 throw not_supported ();
213 protected override bool HasElementTypeImpl ()
218 public override bool IsAssignableFrom (Type c)
220 throw not_supported ();
223 public override bool IsAssignableFrom (TypeInfo typeInfo)
225 if (typeInfo == null)
228 return IsAssignableFrom (typeInfo.AsType ());
231 public override bool IsInstanceOfType (object o)
233 throw not_supported ();
236 protected override bool IsArrayImpl ()
241 protected override bool IsByRefImpl ()
246 protected override bool IsCOMObjectImpl ()
251 protected override bool IsPointerImpl ()
256 protected override bool IsPrimitiveImpl ()
261 protected override bool IsValueTypeImpl ()
263 return base_type != null ? base_type.IsValueType : false;
266 public override object InvokeMember (string name, BindingFlags invokeAttr,
267 Binder binder, object target, object[] args,
268 ParameterModifier[] modifiers,
269 CultureInfo culture, string[] namedParameters)
271 throw not_supported ();
274 public override Type GetElementType ()
276 throw not_supported ();
279 public override Type UnderlyingSystemType {
285 public override Assembly Assembly {
286 get { return tbuilder.Assembly; }
289 public override string AssemblyQualifiedName {
293 public override Type BaseType {
294 get { return base_type; }
297 public override string FullName {
301 public override Guid GUID {
302 get { throw not_supported (); }
305 public override bool IsDefined (Type attributeType, bool inherit)
307 throw not_supported ();
310 public override object[] GetCustomAttributes (bool inherit)
312 throw not_supported ();
315 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
317 throw not_supported ();
321 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
323 throw not_supported ();
326 public override string Name {
330 public override string Namespace {
334 public override Module Module {
335 get { return tbuilder.Module; }
338 public override Type DeclaringType {
339 get { return mbuilder != null ? mbuilder.DeclaringType : tbuilder; }
342 public override Type ReflectedType {
343 get { return DeclaringType; }
346 public override RuntimeTypeHandle TypeHandle {
347 get { throw not_supported (); }
350 public override Type[] GetGenericArguments ()
352 throw new InvalidOperationException ();
355 public override Type GetGenericTypeDefinition ()
357 throw new InvalidOperationException ();
360 public override bool ContainsGenericParameters {
364 public override bool IsGenericParameter {
368 public override bool IsGenericType {
369 get { return false; }
372 public override bool IsGenericTypeDefinition {
373 get { return false; }
376 public override GenericParameterAttributes GenericParameterAttributes {
378 throw new NotSupportedException ();
382 public override int GenericParameterPosition {
383 get { return index; }
386 public override Type[] GetGenericParameterConstraints ()
388 throw new InvalidOperationException ();
391 public override MethodBase DeclaringMethod {
392 get { return mbuilder; }
395 public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
397 if (customBuilder == null)
398 throw new ArgumentNullException ("customBuilder");
400 if (cattrs != null) {
401 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
402 cattrs.CopyTo (new_array, 0);
403 new_array [cattrs.Length] = customBuilder;
406 cattrs = new CustomAttributeBuilder [1];
407 cattrs [0] = customBuilder;
411 [MonoTODO ("unverified implementation")]
412 public void SetCustomAttribute (ConstructorInfo con, byte [] binaryAttribute)
414 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
417 private Exception not_supported ()
419 return new NotSupportedException ();
422 public override string ToString ()
428 public override bool Equals (object o)
430 return base.Equals (o);
434 public override int GetHashCode ()
436 return base.GetHashCode ();
439 public override Type MakeArrayType ()
441 return new ArrayType (this, 0);
444 public override Type MakeArrayType (int rank)
447 throw new IndexOutOfRangeException ();
448 return new ArrayType (this, rank);
451 public override Type MakeByRefType ()
453 return new ByRefType (this);
456 public override Type MakeGenericType (params Type[] typeArguments)
458 throw new InvalidOperationException (Environment.GetResourceString ("Arg_NotGenericTypeDefinition"));
461 public override Type MakePointerType ()
463 return new PointerType (this);
466 internal override bool IsUserType {