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 CustomAttributeBuilder[] cattrs;
54 private GenericParameterAttributes attrs;
57 public void SetBaseTypeConstraint (Type base_type_constraint)
59 this.base_type = base_type_constraint;
63 public void SetInterfaceConstraints (Type[] iface_constraints)
65 this.iface_constraints = iface_constraints;
68 public void SetGenericParameterAttributes (GenericParameterAttributes attrs)
73 internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
74 MethodBuilder mbuilder,
75 string name, int index)
77 this.tbuilder = tbuilder;
78 this.mbuilder = mbuilder;
85 [MethodImplAttribute(MethodImplOptions.InternalCall)]
86 private extern void initialize ();
88 public override bool IsSubclassOf (Type c)
93 return BaseType == c || BaseType.IsSubclassOf (c);
96 protected override TypeAttributes GetAttributeFlagsImpl ()
98 return TypeAttributes.Public;
101 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
103 CallingConventions callConvention,
105 ParameterModifier[] modifiers)
107 throw not_supported ();
110 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
112 throw not_supported ();
115 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
117 throw not_supported ();
120 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
122 throw not_supported ();
125 public override FieldInfo GetField (string name, BindingFlags bindingAttr)
127 throw not_supported ();
130 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
132 throw not_supported ();
135 public override Type GetInterface (string name, bool ignoreCase)
137 throw not_supported ();
140 public override Type[] GetInterfaces ()
142 throw not_supported ();
145 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
147 throw not_supported ();
150 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
152 throw not_supported ();
155 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
157 CallingConventions callConvention,
158 Type[] types, ParameterModifier[] modifiers)
160 throw not_supported ();
163 public override Type GetNestedType (string name, BindingFlags bindingAttr)
165 throw not_supported ();
168 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
170 throw not_supported ();
173 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
175 throw not_supported ();
178 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
179 Binder binder, Type returnType,
181 ParameterModifier[] modifiers)
183 throw not_supported ();
186 protected override bool HasElementTypeImpl ()
191 protected override bool IsArrayImpl ()
196 protected override bool IsByRefImpl ()
201 protected override bool IsCOMObjectImpl ()
206 protected override bool IsPointerImpl ()
211 protected override bool IsPrimitiveImpl ()
216 protected override bool IsValueTypeImpl ()
218 return base_type != null ? base_type.IsValueType : false;
221 public override object InvokeMember (string name, BindingFlags invokeAttr,
222 Binder binder, object target, object[] args,
223 ParameterModifier[] modifiers,
224 CultureInfo culture, string[] namedParameters)
226 throw not_supported ();
229 public override Type GetElementType ()
231 throw not_supported ();
234 public override Type UnderlyingSystemType {
240 public override Assembly Assembly {
241 get { return tbuilder.Assembly; }
244 public override string AssemblyQualifiedName {
248 public override Type BaseType {
249 get { return base_type; }
252 public override string FullName {
256 public override Guid GUID {
257 get { return Guid.Empty; }
260 public override bool IsDefined (Type attributeType, bool inherit)
262 throw not_supported ();
265 public override object[] GetCustomAttributes (bool inherit)
267 throw not_supported ();
270 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
272 throw not_supported ();
275 public override MemberTypes MemberType {
276 get { return MemberTypes.TypeInfo; }
279 public override string Name {
283 public override string Namespace {
287 public override Module Module {
288 get { return tbuilder.Module; }
291 public override Type DeclaringType {
292 get { return mbuilder != null ? mbuilder.DeclaringType : tbuilder; }
295 public override Type ReflectedType {
296 get { 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 ContainsGenericParameters {
322 public override bool IsGenericParameter {
326 public override int GenericParameterPosition {
327 get { return index; }
330 public override GenericParameterAttributes GenericParameterAttributes {
336 public override Type[] GetGenericParameterConstraints ()
338 if (base_type == null) {
339 if (iface_constraints != null)
340 return iface_constraints;
342 return Type.EmptyTypes;
345 if (iface_constraints == null)
346 return new Type[] { base_type };
348 Type[] ret = new Type [iface_constraints.Length + 1];
350 iface_constraints.CopyTo (ret, 1);
354 public override MethodBase DeclaringMethod {
355 get { return mbuilder; }
358 public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
360 if (customBuilder == null)
361 throw new ArgumentNullException ("customBuilder");
363 if (cattrs != null) {
364 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
365 cattrs.CopyTo (new_array, 0);
366 new_array [cattrs.Length] = customBuilder;
369 cattrs = new CustomAttributeBuilder [1];
370 cattrs [0] = customBuilder;
374 private Exception not_supported ()
376 return new NotSupportedException ();
379 public override string ToString ()