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 [StructLayout (LayoutKind.Sequential)]
44 public sealed class GenericTypeParameterBuilder : Type
46 #region Sync with reflection.h
47 private TypeBuilder tbuilder;
48 private MethodBuilder mbuilder;
51 private Type base_type;
52 #pragma warning disable 414
53 private Type[] iface_constraints;
54 private CustomAttributeBuilder[] cattrs;
55 private GenericParameterAttributes attrs;
56 #pragma warning restore
59 public void SetBaseTypeConstraint (Type baseTypeConstraint)
61 this.base_type = baseTypeConstraint ?? typeof (object);
65 public void SetInterfaceConstraints (params Type[] interfaceConstraints)
67 this.iface_constraints = interfaceConstraints;
70 public void SetGenericParameterAttributes (GenericParameterAttributes genericParameterAttributes)
72 this.attrs = genericParameterAttributes;
75 internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
76 MethodBuilder mbuilder,
77 string name, int index)
79 this.tbuilder = tbuilder;
80 this.mbuilder = mbuilder;
87 internal override Type InternalResolve ()
89 return tbuilder.InternalResolve ().GetGenericArguments () [index];
92 [MethodImplAttribute(MethodImplOptions.InternalCall)]
93 private extern void initialize ();
96 public override bool IsSubclassOf (Type c)
98 throw not_supported ();
101 protected override TypeAttributes GetAttributeFlagsImpl ()
104 return TypeAttributes.Public;
106 throw not_supported ();
110 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
112 CallingConventions callConvention,
114 ParameterModifier[] modifiers)
116 throw not_supported ();
120 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
122 throw not_supported ();
125 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
127 throw not_supported ();
130 public override EventInfo[] GetEvents ()
132 throw not_supported ();
135 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
137 throw not_supported ();
140 public override FieldInfo GetField (string name, BindingFlags bindingAttr)
142 throw not_supported ();
145 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
147 throw not_supported ();
150 public override Type GetInterface (string name, bool ignoreCase)
152 throw not_supported ();
155 public override Type[] GetInterfaces ()
157 throw not_supported ();
160 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
162 throw not_supported ();
165 public override MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
167 throw not_supported ();
170 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
172 throw not_supported ();
175 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
177 CallingConventions callConvention,
178 Type[] types, ParameterModifier[] modifiers)
180 throw not_supported ();
183 public override Type GetNestedType (string name, BindingFlags bindingAttr)
185 throw not_supported ();
188 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
190 throw not_supported ();
193 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
195 throw not_supported ();
198 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
199 Binder binder, Type returnType,
201 ParameterModifier[] modifiers)
203 throw not_supported ();
206 protected override bool HasElementTypeImpl ()
211 public override bool IsAssignableFrom (Type c)
213 throw not_supported ();
216 public override bool IsInstanceOfType (object o)
218 throw not_supported ();
221 protected override bool IsArrayImpl ()
226 protected override bool IsByRefImpl ()
231 protected override bool IsCOMObjectImpl ()
236 protected override bool IsPointerImpl ()
241 protected override bool IsPrimitiveImpl ()
246 protected override bool IsValueTypeImpl ()
248 return base_type != null ? base_type.IsValueType : false;
251 public override object InvokeMember (string name, BindingFlags invokeAttr,
252 Binder binder, object target, object[] args,
253 ParameterModifier[] modifiers,
254 CultureInfo culture, string[] namedParameters)
256 throw not_supported ();
259 public override Type GetElementType ()
261 throw not_supported ();
264 public override Type UnderlyingSystemType {
270 public override Assembly Assembly {
271 get { return tbuilder.Assembly; }
274 public override string AssemblyQualifiedName {
278 public override Type BaseType {
279 get { return base_type; }
282 public override string FullName {
286 public override Guid GUID {
287 get { throw not_supported (); }
290 public override bool IsDefined (Type attributeType, bool inherit)
292 throw not_supported ();
295 public override object[] GetCustomAttributes (bool inherit)
297 throw not_supported ();
300 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
302 throw not_supported ();
306 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
308 throw not_supported ();
311 public override string Name {
315 public override string Namespace {
319 public override Module Module {
320 get { return tbuilder.Module; }
323 public override Type DeclaringType {
324 get { return mbuilder != null ? mbuilder.DeclaringType : tbuilder; }
327 public override Type ReflectedType {
328 get { return DeclaringType; }
331 public override RuntimeTypeHandle TypeHandle {
332 get { throw not_supported (); }
335 public override Type[] GetGenericArguments ()
337 throw new InvalidOperationException ();
340 public override Type GetGenericTypeDefinition ()
342 throw new InvalidOperationException ();
345 public override bool ContainsGenericParameters {
349 public override bool IsGenericParameter {
353 public override bool IsGenericType {
354 get { return false; }
357 public override bool IsGenericTypeDefinition {
358 get { return false; }
361 public override GenericParameterAttributes GenericParameterAttributes {
363 throw new NotSupportedException ();
367 public override int GenericParameterPosition {
368 get { return index; }
371 public override Type[] GetGenericParameterConstraints ()
373 throw new InvalidOperationException ();
376 public override MethodBase DeclaringMethod {
377 get { return mbuilder; }
380 public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
382 if (customBuilder == null)
383 throw new ArgumentNullException ("customBuilder");
385 if (cattrs != null) {
386 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
387 cattrs.CopyTo (new_array, 0);
388 new_array [cattrs.Length] = customBuilder;
391 cattrs = new CustomAttributeBuilder [1];
392 cattrs [0] = customBuilder;
396 [MonoTODO ("unverified implementation")]
397 public void SetCustomAttribute (ConstructorInfo con, byte [] binaryAttribute)
399 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
402 private Exception not_supported ()
404 return new NotSupportedException ();
407 public override string ToString ()
413 public override bool Equals (object o)
415 return base.Equals (o);
419 public override int GetHashCode ()
421 return base.GetHashCode ();
424 public override Type MakeArrayType ()
426 return new ArrayType (this, 0);
429 public override Type MakeArrayType (int rank)
432 throw new IndexOutOfRangeException ();
433 return new ArrayType (this, rank);
436 public override Type MakeByRefType ()
438 return new ByRefType (this);
442 public override Type MakeGenericType (params Type [] typeArguments)
444 return base.MakeGenericType (typeArguments);
447 public override Type MakePointerType ()
449 return new PointerType (this);
452 internal override bool IsUserType {