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 : Type
47 #region Sync with reflection.h
48 private TypeBuilder tbuilder;
49 private MethodBuilder mbuilder;
52 private Type base_type;
53 #pragma warning disable 414
54 private Type[] iface_constraints;
55 private CustomAttributeBuilder[] cattrs;
56 private GenericParameterAttributes attrs;
57 #pragma warning restore
60 public void SetBaseTypeConstraint (Type baseTypeConstraint)
62 this.base_type = baseTypeConstraint ?? typeof (object);
66 public void SetInterfaceConstraints (params Type[] interfaceConstraints)
68 this.iface_constraints = interfaceConstraints;
71 public void SetGenericParameterAttributes (GenericParameterAttributes genericParameterAttributes)
73 this.attrs = genericParameterAttributes;
76 internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
77 MethodBuilder mbuilder,
78 string name, int index)
80 this.tbuilder = tbuilder;
81 this.mbuilder = mbuilder;
88 internal override Type InternalResolve ()
90 return tbuilder.InternalResolve ().GetGenericArguments () [index];
93 [MethodImplAttribute(MethodImplOptions.InternalCall)]
94 private extern void initialize ();
97 public override bool IsSubclassOf (Type c)
99 throw not_supported ();
102 protected override TypeAttributes GetAttributeFlagsImpl ()
105 return TypeAttributes.Public;
107 throw not_supported ();
111 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
113 CallingConventions callConvention,
115 ParameterModifier[] modifiers)
117 throw not_supported ();
121 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
123 throw not_supported ();
126 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
128 throw not_supported ();
131 public override EventInfo[] GetEvents ()
133 throw not_supported ();
136 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
138 throw not_supported ();
141 public override FieldInfo GetField (string name, BindingFlags bindingAttr)
143 throw not_supported ();
146 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
148 throw not_supported ();
151 public override Type GetInterface (string name, bool ignoreCase)
153 throw not_supported ();
156 public override Type[] GetInterfaces ()
158 throw not_supported ();
161 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
163 throw not_supported ();
166 public override MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
168 throw not_supported ();
171 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
173 throw not_supported ();
176 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
178 CallingConventions callConvention,
179 Type[] types, ParameterModifier[] modifiers)
181 throw not_supported ();
184 public override Type GetNestedType (string name, BindingFlags bindingAttr)
186 throw not_supported ();
189 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
191 throw not_supported ();
194 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
196 throw not_supported ();
199 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
200 Binder binder, Type returnType,
202 ParameterModifier[] modifiers)
204 throw not_supported ();
207 protected override bool HasElementTypeImpl ()
212 public override bool IsAssignableFrom (Type c)
214 throw not_supported ();
217 public override bool IsInstanceOfType (object o)
219 throw not_supported ();
222 protected override bool IsArrayImpl ()
227 protected override bool IsByRefImpl ()
232 protected override bool IsCOMObjectImpl ()
237 protected override bool IsPointerImpl ()
242 protected override bool IsPrimitiveImpl ()
247 protected override bool IsValueTypeImpl ()
249 return base_type != null ? base_type.IsValueType : false;
252 public override object InvokeMember (string name, BindingFlags invokeAttr,
253 Binder binder, object target, object[] args,
254 ParameterModifier[] modifiers,
255 CultureInfo culture, string[] namedParameters)
257 throw not_supported ();
260 public override Type GetElementType ()
262 throw not_supported ();
265 public override Type UnderlyingSystemType {
271 public override Assembly Assembly {
272 get { return tbuilder.Assembly; }
275 public override string AssemblyQualifiedName {
279 public override Type BaseType {
280 get { return base_type; }
283 public override string FullName {
287 public override Guid GUID {
288 get { throw not_supported (); }
291 public override bool IsDefined (Type attributeType, bool inherit)
293 throw not_supported ();
296 public override object[] GetCustomAttributes (bool inherit)
298 throw not_supported ();
301 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
303 throw not_supported ();
307 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
309 throw not_supported ();
312 public override string Name {
316 public override string Namespace {
320 public override Module Module {
321 get { return tbuilder.Module; }
324 public override Type DeclaringType {
325 get { return mbuilder != null ? mbuilder.DeclaringType : tbuilder; }
328 public override Type ReflectedType {
329 get { return DeclaringType; }
332 public override RuntimeTypeHandle TypeHandle {
333 get { throw not_supported (); }
336 public override Type[] GetGenericArguments ()
338 throw new InvalidOperationException ();
341 public override Type GetGenericTypeDefinition ()
343 throw new InvalidOperationException ();
346 public override bool ContainsGenericParameters {
350 public override bool IsGenericParameter {
354 public override bool IsGenericType {
355 get { return false; }
358 public override bool IsGenericTypeDefinition {
359 get { return false; }
362 public override GenericParameterAttributes GenericParameterAttributes {
364 throw new NotSupportedException ();
368 public override int GenericParameterPosition {
369 get { return index; }
372 public override Type[] GetGenericParameterConstraints ()
374 throw new InvalidOperationException ();
377 public override MethodBase DeclaringMethod {
378 get { return mbuilder; }
381 public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
383 if (customBuilder == null)
384 throw new ArgumentNullException ("customBuilder");
386 if (cattrs != null) {
387 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
388 cattrs.CopyTo (new_array, 0);
389 new_array [cattrs.Length] = customBuilder;
392 cattrs = new CustomAttributeBuilder [1];
393 cattrs [0] = customBuilder;
397 [MonoTODO ("unverified implementation")]
398 public void SetCustomAttribute (ConstructorInfo con, byte [] binaryAttribute)
400 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
403 private Exception not_supported ()
405 return new NotSupportedException ();
408 public override string ToString ()
414 public override bool Equals (object o)
416 return base.Equals (o);
420 public override int GetHashCode ()
422 return base.GetHashCode ();
425 public override Type MakeArrayType ()
427 return new ArrayType (this, 0);
430 public override Type MakeArrayType (int rank)
433 throw new IndexOutOfRangeException ();
434 return new ArrayType (this, rank);
437 public override Type MakeByRefType ()
439 return new ByRefType (this);
443 public override Type MakeGenericType (params Type [] typeArguments)
445 return base.MakeGenericType (typeArguments);
448 public override Type MakePointerType ()
450 return new PointerType (this);
453 internal override bool IsUserType {