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 #if NET_2_0 || BOOTSTRAP_NET_2_0
41 namespace System.Reflection.Emit
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 private Type[] iface_constraints;
53 private GenericParameterAttributes attrs;
56 public void SetBaseTypeConstraint (Type base_type_constraint)
58 this.base_type = base_type_constraint;
62 public void SetInterfaceConstraints (Type[] iface_constraints)
64 this.iface_constraints = iface_constraints;
67 public void SetGenericParameterAttributes (GenericParameterAttributes attrs)
72 internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
73 MethodBuilder mbuilder,
74 string name, int index)
76 this.tbuilder = tbuilder;
77 this.mbuilder = mbuilder;
84 [MethodImplAttribute(MethodImplOptions.InternalCall)]
85 private extern void initialize ();
87 public override bool IsSubclassOf (Type c)
92 return BaseType == c || BaseType.IsSubclassOf (c);
95 protected override TypeAttributes GetAttributeFlagsImpl ()
97 return TypeAttributes.Public;
100 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
102 CallingConventions callConvention,
104 ParameterModifier[] modifiers)
106 throw not_supported ();
109 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
111 throw not_supported ();
114 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
116 throw not_supported ();
119 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
121 throw not_supported ();
124 public override FieldInfo GetField (string name, BindingFlags bindingAttr)
126 throw not_supported ();
129 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
131 throw not_supported ();
134 public override Type GetInterface (string name, bool ignoreCase)
136 throw not_supported ();
139 public override Type[] GetInterfaces ()
141 throw not_supported ();
144 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
146 throw not_supported ();
149 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
151 throw not_supported ();
154 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
156 CallingConventions callConvention,
157 Type[] types, ParameterModifier[] modifiers)
159 throw not_supported ();
162 public override Type GetNestedType (string name, BindingFlags bindingAttr)
164 throw not_supported ();
167 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
169 throw not_supported ();
172 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
174 throw not_supported ();
177 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
178 Binder binder, Type returnType,
180 ParameterModifier[] modifiers)
182 throw not_supported ();
185 protected override bool HasElementTypeImpl ()
190 protected override bool IsArrayImpl ()
195 protected override bool IsByRefImpl ()
200 protected override bool IsCOMObjectImpl ()
205 protected override bool IsPointerImpl ()
210 protected override bool IsPrimitiveImpl ()
215 protected override bool IsValueTypeImpl ()
217 return base_type != null ? base_type.IsValueType : false;
220 public override object InvokeMember (string name, BindingFlags invokeAttr,
221 Binder binder, object target, object[] args,
222 ParameterModifier[] modifiers,
223 CultureInfo culture, string[] namedParameters)
225 throw not_supported ();
228 public override Type GetElementType ()
230 throw not_supported ();
233 public override Type UnderlyingSystemType {
239 public override Assembly Assembly {
240 get { return tbuilder.Assembly; }
243 public override string AssemblyQualifiedName {
247 public override Type BaseType {
248 get { return base_type; }
251 public override string FullName {
255 public override Guid GUID {
256 get { return Guid.Empty; }
259 public override bool IsDefined (Type attributeType, bool inherit)
261 throw not_supported ();
264 public override object[] GetCustomAttributes (bool inherit)
266 throw not_supported ();
269 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
271 throw not_supported ();
274 public override MemberTypes MemberType {
275 get { return MemberTypes.TypeInfo; }
278 public override string Name {
282 public override string Namespace {
286 public override Module Module {
287 get { return tbuilder.Module; }
290 public override Type DeclaringType {
291 get { return mbuilder != null ? null : tbuilder; }
294 public override Type ReflectedType {
296 return DeclaringType;
300 public override RuntimeTypeHandle TypeHandle {
301 get { throw not_supported (); }
304 public override int GetArrayRank ()
306 throw not_supported ();
309 public override Type[] GetGenericArguments ()
311 throw not_supported ();
314 public override Type GetGenericTypeDefinition ()
316 throw not_supported ();
319 public override bool HasGenericArguments {
320 get { return false; }
323 public override bool ContainsGenericParameters {
327 public override bool IsGenericParameter {
331 public override int GenericParameterPosition {
332 get { return index; }
335 public override GenericParameterAttributes GenericParameterAttributes {
341 public override Type[] GetGenericParameterConstraints ()
343 if (base_type == null) {
344 if (iface_constraints != null)
345 return iface_constraints;
347 return Type.EmptyTypes;
350 if (iface_constraints == null)
351 return new Type[] { base_type };
353 Type[] ret = new Type [iface_constraints.Length + 1];
355 iface_constraints.CopyTo (ret, 1);
359 public override MethodInfo DeclaringMethod {
360 get { return mbuilder; }
363 private Exception not_supported ()
365 return new NotSupportedException ();
368 public override string ToString ()