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.Globalization;
37 using System.Runtime.Serialization;
39 #if NET_2_0 || BOOTSTRAP_NET_2_0
40 namespace System.Reflection.Emit
42 public sealed class GenericTypeParameterBuilder : Type
44 #region Sync with reflection.h
45 private TypeBuilder tbuilder;
46 private MethodBuilder mbuilder;
49 private Type base_type;
50 private Type[] iface_constraints;
51 private GenericParameterAttributes attrs;
54 public void SetBaseTypeConstraint (Type base_type_constraint)
56 this.base_type = base_type_constraint;
59 public void SetInterfaceConstraints (Type[] iface_constraints)
61 this.iface_constraints = iface_constraints;
64 public void SetGenericParameterAttributes (GenericParameterAttributes attrs)
69 internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
70 MethodBuilder mbuilder,
71 string name, int index)
73 this.tbuilder = tbuilder;
74 this.mbuilder = mbuilder;
81 [MethodImplAttribute(MethodImplOptions.InternalCall)]
82 private extern void initialize ();
84 public override bool IsSubclassOf (Type c)
89 return BaseType == c || BaseType.IsSubclassOf (c);
92 protected override TypeAttributes GetAttributeFlagsImpl ()
94 return TypeAttributes.Public;
97 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
99 CallingConventions callConvention,
101 ParameterModifier[] modifiers)
103 throw not_supported ();
106 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
108 throw not_supported ();
111 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
113 throw not_supported ();
116 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
118 throw not_supported ();
121 public override FieldInfo GetField (string name, BindingFlags bindingAttr)
123 throw not_supported ();
126 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
128 throw not_supported ();
131 public override Type GetInterface (string name, bool ignoreCase)
133 throw not_supported ();
136 public override Type[] GetInterfaces ()
138 throw not_supported ();
141 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
143 throw not_supported ();
146 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
148 throw not_supported ();
151 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
153 CallingConventions callConvention,
154 Type[] types, ParameterModifier[] modifiers)
156 throw not_supported ();
159 public override Type GetNestedType (string name, BindingFlags bindingAttr)
161 throw not_supported ();
164 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
166 throw not_supported ();
169 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
171 throw not_supported ();
174 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
175 Binder binder, Type returnType,
177 ParameterModifier[] modifiers)
179 throw not_supported ();
182 protected override bool HasElementTypeImpl ()
187 protected override bool IsArrayImpl ()
192 protected override bool IsByRefImpl ()
197 protected override bool IsCOMObjectImpl ()
202 protected override bool IsPointerImpl ()
207 protected override bool IsPrimitiveImpl ()
212 protected override bool IsValueTypeImpl ()
214 return base_type != null ? base_type.IsValueType : false;
217 public override object InvokeMember (string name, BindingFlags invokeAttr,
218 Binder binder, object target, object[] args,
219 ParameterModifier[] modifiers,
220 CultureInfo culture, string[] namedParameters)
222 throw not_supported ();
225 public override Type GetElementType ()
227 throw not_supported ();
230 public override Type UnderlyingSystemType {
236 public override Assembly Assembly {
237 get { return tbuilder.Assembly; }
240 public override string AssemblyQualifiedName {
244 public override Type BaseType {
245 get { return base_type; }
248 public override string FullName {
252 public override Guid GUID {
253 get { return Guid.Empty; }
256 public override bool IsDefined (Type attributeType, bool inherit)
258 throw not_supported ();
261 public override object[] GetCustomAttributes (bool inherit)
263 throw not_supported ();
266 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
268 throw not_supported ();
271 public override MemberTypes MemberType {
272 get { return MemberTypes.TypeInfo; }
275 public override string Name {
279 public override string Namespace {
283 public override Module Module {
284 get { return tbuilder.Module; }
287 public override Type DeclaringType {
288 get { return mbuilder != null ? null : tbuilder; }
291 public override Type ReflectedType {
293 return DeclaringType;
297 public override RuntimeTypeHandle TypeHandle {
298 get { throw not_supported (); }
301 public override int GetArrayRank ()
303 throw not_supported ();
306 public override Type[] GetGenericArguments ()
308 throw not_supported ();
311 public override Type GetGenericTypeDefinition ()
313 throw not_supported ();
316 public override bool HasGenericArguments {
317 get { return false; }
320 public override bool ContainsGenericParameters {
324 public override bool IsGenericParameter {
328 public override int GenericParameterPosition {
329 get { return index; }
332 public override GenericParameterAttributes GenericParameterAttributes {
338 public override Type[] GetGenericParameterConstraints ()
340 if (base_type == null) {
341 if (iface_constraints != null)
342 return iface_constraints;
344 return Type.EmptyTypes;
347 if (iface_constraints == null)
348 return new Type[] { base_type };
350 Type[] ret = new Type [iface_constraints.Length + 1];
352 iface_constraints.CopyTo (ret, 1);
356 public override MethodInfo DeclaringMethod {
357 get { return mbuilder; }
360 private Exception not_supported ()
362 return new NotSupportedException ();
365 public override string ToString ()