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;
87 internal override Type InternalResolve ()
90 return MethodBase.GetMethodFromHandle (mbuilder.MethodHandleInternal).GetGenericArguments () [index];
91 return tbuilder.InternalResolve ().GetGenericArguments () [index];
94 internal override Type RuntimeResolve ()
97 return MethodBase.GetMethodFromHandle (mbuilder.MethodHandleInternal, mbuilder.TypeBuilder.RuntimeResolve ().TypeHandle).GetGenericArguments () [index];
98 return tbuilder.RuntimeResolve ().GetGenericArguments () [index];
102 public override bool IsSubclassOf (Type c)
104 throw not_supported ();
107 protected override TypeAttributes GetAttributeFlagsImpl ()
109 return TypeAttributes.Public;
112 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
114 CallingConventions callConvention,
116 ParameterModifier[] modifiers)
118 throw not_supported ();
122 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
124 throw not_supported ();
127 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
129 throw not_supported ();
132 public override EventInfo[] GetEvents ()
134 throw not_supported ();
137 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
139 throw not_supported ();
142 public override FieldInfo GetField (string name, BindingFlags bindingAttr)
144 throw not_supported ();
147 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
149 throw not_supported ();
152 public override Type GetInterface (string name, bool ignoreCase)
154 throw not_supported ();
157 public override Type[] GetInterfaces ()
159 throw not_supported ();
162 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
164 throw not_supported ();
167 public override MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
169 throw not_supported ();
172 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
174 throw not_supported ();
177 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
179 CallingConventions callConvention,
180 Type[] types, ParameterModifier[] modifiers)
182 throw not_supported ();
185 public override Type GetNestedType (string name, BindingFlags bindingAttr)
187 throw not_supported ();
190 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
192 throw not_supported ();
195 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
197 throw not_supported ();
200 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
201 Binder binder, Type returnType,
203 ParameterModifier[] modifiers)
205 throw not_supported ();
208 protected override bool HasElementTypeImpl ()
213 public override bool IsAssignableFrom (Type c)
215 throw not_supported ();
218 public override bool IsAssignableFrom (TypeInfo typeInfo)
220 if (typeInfo == null)
223 return IsAssignableFrom (typeInfo.AsType ());
226 public override bool IsInstanceOfType (object o)
228 throw not_supported ();
231 protected override bool IsArrayImpl ()
236 protected override bool IsByRefImpl ()
241 protected override bool IsCOMObjectImpl ()
246 protected override bool IsPointerImpl ()
251 protected override bool IsPrimitiveImpl ()
256 protected override bool IsValueTypeImpl ()
258 return base_type != null ? base_type.IsValueType : false;
261 public override object InvokeMember (string name, BindingFlags invokeAttr,
262 Binder binder, object target, object[] args,
263 ParameterModifier[] modifiers,
264 CultureInfo culture, string[] namedParameters)
266 throw not_supported ();
269 public override Type GetElementType ()
271 throw not_supported ();
274 public override Type UnderlyingSystemType {
280 public override Assembly Assembly {
281 get { return tbuilder.Assembly; }
284 public override string AssemblyQualifiedName {
288 public override Type BaseType {
289 get { return base_type; }
292 public override string FullName {
296 public override Guid GUID {
297 get { throw not_supported (); }
300 public override bool IsDefined (Type attributeType, bool inherit)
302 throw not_supported ();
305 public override object[] GetCustomAttributes (bool inherit)
307 throw not_supported ();
310 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
312 throw not_supported ();
316 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
318 throw not_supported ();
321 public override string Name {
325 public override string Namespace {
329 public override Module Module {
330 get { return tbuilder.Module; }
333 public override Type DeclaringType {
334 get { return mbuilder != null ? mbuilder.DeclaringType : tbuilder; }
337 public override Type ReflectedType {
338 get { return DeclaringType; }
341 public override RuntimeTypeHandle TypeHandle {
342 get { throw not_supported (); }
345 public override Type[] GetGenericArguments ()
347 throw new InvalidOperationException ();
350 public override Type GetGenericTypeDefinition ()
352 throw new InvalidOperationException ();
355 public override bool ContainsGenericParameters {
359 public override bool IsGenericParameter {
363 public override bool IsGenericType {
364 get { return false; }
367 public override bool IsGenericTypeDefinition {
368 get { return false; }
371 public override GenericParameterAttributes GenericParameterAttributes {
373 throw new NotSupportedException ();
377 public override int GenericParameterPosition {
378 get { return index; }
381 public override Type[] GetGenericParameterConstraints ()
383 throw new InvalidOperationException ();
386 public override MethodBase DeclaringMethod {
387 get { return mbuilder; }
390 public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
392 if (customBuilder == null)
393 throw new ArgumentNullException ("customBuilder");
395 if (cattrs != null) {
396 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
397 cattrs.CopyTo (new_array, 0);
398 new_array [cattrs.Length] = customBuilder;
401 cattrs = new CustomAttributeBuilder [1];
402 cattrs [0] = customBuilder;
406 [MonoTODO ("unverified implementation")]
407 public void SetCustomAttribute (ConstructorInfo con, byte [] binaryAttribute)
409 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
412 private Exception not_supported ()
414 return new NotSupportedException ();
417 public override string ToString ()
423 public override bool Equals (object o)
425 return base.Equals (o);
429 public override int GetHashCode ()
431 return base.GetHashCode ();
434 public override Type MakeArrayType ()
436 return new ArrayType (this, 0);
439 public override Type MakeArrayType (int rank)
442 throw new IndexOutOfRangeException ();
443 return new ArrayType (this, rank);
446 public override Type MakeByRefType ()
448 return new ByRefType (this);
451 public override Type MakeGenericType (params Type[] typeArguments)
453 throw new InvalidOperationException (Environment.GetResourceString ("Arg_NotGenericTypeDefinition"));
456 public override Type MakePointerType ()
458 return new PointerType (this);
461 internal override bool IsUserType {