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 ()
91 return tbuilder.InternalResolve ().GetGenericArguments () [index];
94 [MethodImplAttribute(MethodImplOptions.InternalCall)]
95 private extern void initialize ();
98 public override bool IsSubclassOf (Type c)
100 throw not_supported ();
103 protected override TypeAttributes GetAttributeFlagsImpl ()
105 return TypeAttributes.Public;
108 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
110 CallingConventions callConvention,
112 ParameterModifier[] modifiers)
114 throw not_supported ();
118 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
120 throw not_supported ();
123 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
125 throw not_supported ();
128 public override EventInfo[] GetEvents ()
130 throw not_supported ();
133 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
135 throw not_supported ();
138 public override FieldInfo GetField (string name, BindingFlags bindingAttr)
140 throw not_supported ();
143 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
145 throw not_supported ();
148 public override Type GetInterface (string name, bool ignoreCase)
150 throw not_supported ();
153 public override Type[] GetInterfaces ()
155 throw not_supported ();
158 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
160 throw not_supported ();
163 public override MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
165 throw not_supported ();
168 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
170 throw not_supported ();
173 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
175 CallingConventions callConvention,
176 Type[] types, ParameterModifier[] modifiers)
178 throw not_supported ();
181 public override Type GetNestedType (string name, BindingFlags bindingAttr)
183 throw not_supported ();
186 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
188 throw not_supported ();
191 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
193 throw not_supported ();
196 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
197 Binder binder, Type returnType,
199 ParameterModifier[] modifiers)
201 throw not_supported ();
204 protected override bool HasElementTypeImpl ()
209 public override bool IsAssignableFrom (Type c)
211 throw not_supported ();
214 public override bool IsInstanceOfType (object o)
216 throw not_supported ();
219 protected override bool IsArrayImpl ()
224 protected override bool IsByRefImpl ()
229 protected override bool IsCOMObjectImpl ()
234 protected override bool IsPointerImpl ()
239 protected override bool IsPrimitiveImpl ()
244 protected override bool IsValueTypeImpl ()
246 return base_type != null ? base_type.IsValueType : false;
249 public override object InvokeMember (string name, BindingFlags invokeAttr,
250 Binder binder, object target, object[] args,
251 ParameterModifier[] modifiers,
252 CultureInfo culture, string[] namedParameters)
254 throw not_supported ();
257 public override Type GetElementType ()
259 throw not_supported ();
262 public override Type UnderlyingSystemType {
268 public override Assembly Assembly {
269 get { return tbuilder.Assembly; }
272 public override string AssemblyQualifiedName {
276 public override Type BaseType {
277 get { return base_type; }
280 public override string FullName {
284 public override Guid GUID {
285 get { throw not_supported (); }
288 public override bool IsDefined (Type attributeType, bool inherit)
290 throw not_supported ();
293 public override object[] GetCustomAttributes (bool inherit)
295 throw not_supported ();
298 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
300 throw not_supported ();
304 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
306 throw not_supported ();
309 public override string Name {
313 public override string Namespace {
317 public override Module Module {
318 get { return tbuilder.Module; }
321 public override Type DeclaringType {
322 get { return mbuilder != null ? mbuilder.DeclaringType : tbuilder; }
325 public override Type ReflectedType {
326 get { return DeclaringType; }
329 public override RuntimeTypeHandle TypeHandle {
330 get { throw not_supported (); }
333 public override Type[] GetGenericArguments ()
335 throw new InvalidOperationException ();
338 public override Type GetGenericTypeDefinition ()
340 throw new InvalidOperationException ();
343 public override bool ContainsGenericParameters {
347 public override bool IsGenericParameter {
351 public override bool IsGenericType {
352 get { return false; }
355 public override bool IsGenericTypeDefinition {
356 get { return false; }
359 public override GenericParameterAttributes GenericParameterAttributes {
361 throw new NotSupportedException ();
365 public override int GenericParameterPosition {
366 get { return index; }
369 public override Type[] GetGenericParameterConstraints ()
371 throw new InvalidOperationException ();
374 public override MethodBase DeclaringMethod {
375 get { return mbuilder; }
378 public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
380 if (customBuilder == null)
381 throw new ArgumentNullException ("customBuilder");
383 if (cattrs != null) {
384 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
385 cattrs.CopyTo (new_array, 0);
386 new_array [cattrs.Length] = customBuilder;
389 cattrs = new CustomAttributeBuilder [1];
390 cattrs [0] = customBuilder;
394 [MonoTODO ("unverified implementation")]
395 public void SetCustomAttribute (ConstructorInfo con, byte [] binaryAttribute)
397 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
400 private Exception not_supported ()
402 return new NotSupportedException ();
405 public override string ToString ()
411 public override bool Equals (object o)
413 return base.Equals (o);
417 public override int GetHashCode ()
419 return base.GetHashCode ();
422 public override Type MakeArrayType ()
424 return new ArrayType (this, 0);
427 public override Type MakeArrayType (int rank)
430 throw new IndexOutOfRangeException ();
431 return new ArrayType (this, rank);
434 public override Type MakeByRefType ()
436 return new ByRefType (this);
439 public override Type MakeGenericType (params Type[] typeArguments)
441 throw new InvalidOperationException (Environment.GetResourceString ("Arg_NotGenericTypeDefinition"));
444 public override Type MakePointerType ()
446 return new PointerType (this);
449 internal override bool IsUserType {