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 ()
216 // return base_type != null ? base_type.IsValueType : false;
219 public override object InvokeMember (string name, BindingFlags invokeAttr,
220 Binder binder, object target, object[] args,
221 ParameterModifier[] modifiers,
222 CultureInfo culture, string[] namedParameters)
224 throw not_supported ();
227 public override Type GetElementType ()
229 throw not_supported ();
232 public override Type UnderlyingSystemType {
238 public override Assembly Assembly {
239 get { return tbuilder.Assembly; }
242 public override string AssemblyQualifiedName {
246 public override Type BaseType {
247 get { return base_type; }
250 public override string FullName {
254 public override Guid GUID {
255 get { return Guid.Empty; }
258 public override bool IsDefined (Type attributeType, bool inherit)
260 throw not_supported ();
263 public override object[] GetCustomAttributes (bool inherit)
265 throw not_supported ();
268 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
270 throw not_supported ();
273 public override MemberTypes MemberType {
274 get { return MemberTypes.TypeInfo; }
277 public override string Name {
281 public override string Namespace {
285 public override Module Module {
286 get { return tbuilder.Module; }
289 public override Type DeclaringType {
290 get { return mbuilder != null ? null : tbuilder; }
293 public override Type ReflectedType {
295 return DeclaringType;
299 public override RuntimeTypeHandle TypeHandle {
300 get { throw not_supported (); }
303 public override int GetArrayRank ()
305 throw not_supported ();
308 public override Type[] GetGenericArguments ()
310 throw not_supported ();
313 public override Type GetGenericTypeDefinition ()
315 throw not_supported ();
318 public override bool HasGenericArguments {
319 get { return false; }
322 public override bool ContainsGenericParameters {
326 public override bool IsGenericParameter {
330 public override int GenericParameterPosition {
331 get { return index; }
334 public override GenericParameterAttributes GenericParameterAttributes {
340 public override Type[] GetGenericParameterConstraints ()
342 if (base_type == null) {
343 if (iface_constraints != null)
344 return iface_constraints;
346 return Type.EmptyTypes;
349 if (iface_constraints == null)
350 return new Type[] { base_type };
352 Type[] ret = new Type [iface_constraints.Length + 1];
354 iface_constraints.CopyTo (ret, 1);
358 public override MethodInfo DeclaringMethod {
359 get { return mbuilder; }
362 private Exception not_supported ()
364 return new NotSupportedException ();
367 public override string ToString ()