2 // System.Reflection.Emit/TypeBuilder.cs
5 // Paolo Molaro (lupus@ximian.com)
7 // (C) 2001 Ximian, Inc. http://www.ximian.com
11 using System.Reflection;
12 using System.Reflection.Emit;
13 using System.Runtime.CompilerServices;
14 using System.Runtime.InteropServices;
15 using System.Globalization;
16 using System.Collections;
17 using System.Security;
18 using System.Security.Permissions;
20 namespace System.Reflection.Emit {
21 public sealed class TypeBuilder : Type {
23 private string nspace;
25 private Type nesting_type;
26 private Type[] interfaces;
27 private MethodBuilder[] methods;
28 private ConstructorBuilder[] ctors;
29 private PropertyBuilder[] properties;
30 private FieldBuilder[] fields;
31 private EventBuilder[] events;
32 private CustomAttributeBuilder[] cattrs;
33 internal TypeBuilder[] subtypes;
34 private TypeAttributes attrs;
35 private int table_idx;
36 private ModuleBuilder pmodule;
37 private int class_size;
38 private PackingSize packing_size;
42 public const int UnspecifiedTypeSize = 0;
44 protected override TypeAttributes GetAttributeFlagsImpl () {
48 [MethodImplAttribute(MethodImplOptions.InternalCall)]
49 private extern void setup_internal_class (TypeBuilder tb);
51 [MethodImplAttribute(MethodImplOptions.InternalCall)]
52 private extern void create_internal_class (TypeBuilder tb);
54 internal TypeBuilder (ModuleBuilder mb, TypeAttributes attr) {
58 fullname = this.tname = "<Module>";
61 setup_internal_class (this);
64 internal TypeBuilder (ModuleBuilder mb, string name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packing_size, int type_size, Type nesting_type) {
68 this.class_size = type_size;
69 this.packing_size = packing_size;
70 this.nesting_type = nesting_type;
71 sep_index = name.LastIndexOf('.');
72 if (sep_index != -1) {
73 this.tname = name.Substring (sep_index + 1);
74 this.nspace = name.Substring (0, sep_index);
79 if (interfaces != null) {
80 this.interfaces = new Type[interfaces.Length];
81 System.Array.Copy (interfaces, this.interfaces, interfaces.Length);
85 table_idx = mb.get_next_table_index (this, 0x02, true);
86 setup_internal_class (this);
87 fullname = GetFullName ();
90 public override Assembly Assembly {
91 get {return pmodule.Assembly;}
94 public override string AssemblyQualifiedName {
96 return fullname + ", " + Assembly.GetName().FullName;
99 public override Type BaseType {
104 public override Type DeclaringType {get {return nesting_type;}}
107 public override Type UnderlyingSystemType {
109 // This should return the type itself for non-enum types but
111 if (fields != null) {
112 foreach (FieldBuilder f in fields) {
113 if ((f.Attributes & FieldAttributes.Static) == 0)
117 throw new InvalidOperationException ("Underlying type information on enumeration is not specified.");
121 string GetFullName () {
122 if (nesting_type != null)
123 return String.Concat (nesting_type.FullName, "+", tname);
124 if ((nspace != null) && (nspace.Length > 0))
125 return String.Concat (nspace, ".", tname);
129 public override string FullName {
135 public override Guid GUID {
137 throw not_supported ();
141 public override Module Module {
142 get {return pmodule;}
144 public override string Name {
147 public override string Namespace {
150 public PackingSize PackingSize {
151 get {return packing_size;}
154 get { return class_size; }
156 public override Type ReflectedType {get {return nesting_type;}}
157 public override MemberTypes MemberType {
158 get {return MemberTypes.TypeInfo;}
162 public void AddDeclarativeSecurity( SecurityAction action, PermissionSet pset) {
163 throw new NotImplementedException ();
166 public void AddInterfaceImplementation( Type interfaceType) {
167 if (interfaceType == null)
168 throw new ArgumentNullException ("interfaceType");
170 throw not_after_created ();
172 if (interfaces != null) {
173 // Check for duplicates
174 foreach (Type t in interfaces)
175 if (t == interfaceType)
178 Type[] ifnew = new Type [interfaces.Length + 1];
179 interfaces.CopyTo (ifnew, 0);
180 ifnew [interfaces.Length] = interfaceType;
183 interfaces = new Type [1];
184 interfaces [0] = interfaceType;
189 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr, Binder binder,
190 CallingConventions callConvention, Type[] types,
191 ParameterModifier[] modifiers)
196 ConstructorBuilder found = null;
199 foreach (ConstructorBuilder cb in ctors){
200 if (callConvention != CallingConventions.Any && cb.CallingConvention != callConvention)
210 throw new AmbiguousMatchException ();
213 MethodBase[] match = new MethodBase [count];
218 foreach (ConstructorInfo m in ctors) {
219 if (callConvention != CallingConventions.Any && m.CallingConvention != callConvention)
225 binder = Binder.DefaultBinder;
226 return (ConstructorInfo)binder.SelectMethod (bindingAttr, match, types, modifiers);
229 public override bool IsDefined( Type attributeType, bool inherit)
231 throw not_supported ();
234 public override object[] GetCustomAttributes(bool inherit)
236 throw not_supported ();
239 public override object[] GetCustomAttributes(Type attributeType, bool inherit)
241 throw not_supported ();
244 public TypeBuilder DefineNestedType (string name) {
245 return DefineNestedType (name, TypeAttributes.NestedPrivate, pmodule.assemblyb.corlib_object_type, null);
248 public TypeBuilder DefineNestedType (string name, TypeAttributes attr) {
249 return DefineNestedType (name, attr, pmodule.assemblyb.corlib_object_type, null);
252 public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent) {
253 return DefineNestedType (name, attr, parent, null);
256 private TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, Type[] interfaces,
257 PackingSize packsize, int typesize)
259 check_name ("name", name);
260 // Visibility must be NestedXXX
262 if (((attrs & TypeAttributes.VisibilityMask) == TypeAttributes.Public) ||
263 ((attrs & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic))
264 throw new ArgumentException ("attr", "Bad type flags for nested type.");
266 if (interfaces != null)
267 foreach (Type iface in interfaces)
269 throw new ArgumentNullException ("interfaces");
271 TypeBuilder res = new TypeBuilder (pmodule, name, attr, parent, interfaces, packsize, typesize, this);
272 res.fullname = res.GetFullName ();
273 pmodule.RegisterTypeName (res, res.fullname);
274 if (subtypes != null) {
275 TypeBuilder[] new_types = new TypeBuilder [subtypes.Length + 1];
276 System.Array.Copy (subtypes, new_types, subtypes.Length);
277 new_types [subtypes.Length] = res;
278 subtypes = new_types;
280 subtypes = new TypeBuilder [1];
286 public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, Type[] interfaces) {
287 return DefineNestedType (name, attr, parent, interfaces, PackingSize.Unspecified, UnspecifiedTypeSize);
290 public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, int typesize) {
291 return DefineNestedType (name, attr, parent, null, PackingSize.Unspecified, typesize);
294 public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, PackingSize packsize) {
295 return DefineNestedType (name, attr, parent, null, packsize, UnspecifiedTypeSize);
298 public ConstructorBuilder DefineConstructor (MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes)
301 throw not_after_created ();
302 ConstructorBuilder cb = new ConstructorBuilder (this, attributes, callingConvention, parameterTypes);
304 ConstructorBuilder[] new_ctors = new ConstructorBuilder [ctors.Length+1];
305 System.Array.Copy (ctors, new_ctors, ctors.Length);
306 new_ctors [ctors.Length] = cb;
309 ctors = new ConstructorBuilder [1];
315 public ConstructorBuilder DefineDefaultConstructor (MethodAttributes attributes)
317 ConstructorBuilder cb = DefineConstructor (attributes, CallingConventions.Standard, null);
319 ConstructorInfo parent_constructor = parent.GetConstructor (
320 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
321 null, Type.EmptyTypes, null);
323 ILGenerator ig = cb.GetILGenerator ();
324 if (parent_constructor != null){
325 ig.Emit (OpCodes.Ldarg_0);
326 ig.Emit (OpCodes.Call, parent_constructor);
328 ig.Emit (OpCodes.Ret);
332 public MethodBuilder DefineMethod( string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes) {
333 return DefineMethod (name, attributes, CallingConventions.Standard, returnType, parameterTypes);
336 private void append_method (MethodBuilder mb) {
337 if (methods != null) {
338 MethodBuilder[] new_methods = new MethodBuilder [methods.Length+1];
339 System.Array.Copy (methods, new_methods, methods.Length);
340 new_methods [methods.Length] = mb;
341 methods = new_methods;
343 methods = new MethodBuilder [1];
348 public MethodBuilder DefineMethod( string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
349 check_name ("name", name);
351 throw not_after_created ();
353 !((attributes & MethodAttributes.Abstract) != 0) ||
354 !((attributes & MethodAttributes.Virtual) != 0)))
355 throw new ArgumentException ("attributes", "Interface method must be abstract and virtual.");
357 MethodBuilder res = new MethodBuilder (this, name, attributes, callingConvention, returnType, parameterTypes);
362 public MethodBuilder DefinePInvokeMethod (string name, string dllName, string entryName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet) {
363 check_name ("name", name);
364 check_name ("dllName", dllName);
365 check_name ("entryName", entryName);
366 if ((attributes & MethodAttributes.Abstract) != 0)
367 throw new ArgumentException ("attributes", "PInvoke methods must be static and native and cannot be abstract.");
369 throw new ArgumentException ("PInvoke methods cannot exist on interfaces.");
371 throw not_after_created ();
373 MethodBuilder res = new MethodBuilder (this, name, attributes, callingConvention, returnType, parameterTypes,
374 dllName, entryName, nativeCallConv, nativeCharSet);
379 public MethodBuilder DefinePInvokeMethod (string name, string dllName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet) {
380 return DefinePInvokeMethod (name, dllName, name, attributes, callingConvention, returnType, parameterTypes,
381 nativeCallConv, nativeCharSet);
384 public void DefineMethodOverride( MethodInfo methodInfoBody, MethodInfo methodInfoDeclaration) {
385 if (methodInfoBody == null)
386 throw new ArgumentNullException ("methodInfoBody");
387 if (methodInfoDeclaration == null)
388 throw new ArgumentNullException ("methodInfoDeclaration");
390 throw not_after_created ();
392 if (methodInfoBody is MethodBuilder) {
393 MethodBuilder mb = (MethodBuilder)methodInfoBody;
394 mb.set_override (methodInfoDeclaration);
398 public FieldBuilder DefineField( string fieldName, Type type, FieldAttributes attributes) {
399 check_name ("fieldName", fieldName);
400 if (type == typeof (void))
401 throw new ArgumentException ("type", "Bad field type in defining field.");
403 throw not_after_created ();
405 FieldBuilder res = new FieldBuilder (this, fieldName, type, attributes);
406 if (fields != null) {
407 FieldBuilder[] new_fields = new FieldBuilder [fields.Length+1];
408 System.Array.Copy (fields, new_fields, fields.Length);
409 new_fields [fields.Length] = res;
412 fields = new FieldBuilder [1];
414 create_internal_class (this);
419 public PropertyBuilder DefineProperty( string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes) {
420 check_name ("name", name);
421 if (parameterTypes != null)
422 foreach (Type param in parameterTypes)
424 throw new ArgumentNullException ("parameterTypes");
426 throw not_after_created ();
428 PropertyBuilder res = new PropertyBuilder (this, name, attributes, returnType, parameterTypes);
430 if (properties != null) {
431 PropertyBuilder[] new_properties = new PropertyBuilder [properties.Length+1];
432 System.Array.Copy (properties, new_properties, properties.Length);
433 new_properties [properties.Length] = res;
434 properties = new_properties;
436 properties = new PropertyBuilder [1];
437 properties [0] = res;
443 public ConstructorBuilder DefineTypeInitializer() {
445 throw not_after_created ();
447 throw new NotImplementedException ();
450 [MethodImplAttribute(MethodImplOptions.InternalCall)]
451 private extern Type create_runtime_class (TypeBuilder tb);
453 public Type CreateType() {
454 /* handle nesting_type */
456 throw not_after_created ();
457 if (methods != null) {
458 foreach (MethodBuilder method in methods) {
464 // On classes, define a default constructor if not provided
466 if (!(IsInterface || IsValueType) && (ctors == null) && (tname != "<Module>"))
467 DefineDefaultConstructor (MethodAttributes.Public);
470 foreach (ConstructorBuilder ctor in ctors)
474 created = create_runtime_class (this);
480 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
483 return new ConstructorInfo [0];
484 ArrayList l = new ArrayList ();
486 MethodAttributes mattrs;
488 foreach (ConstructorBuilder c in ctors) {
490 mattrs = c.Attributes;
491 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
492 if ((bindingAttr & BindingFlags.Public) != 0)
495 if ((bindingAttr & BindingFlags.NonPublic) != 0)
501 if ((mattrs & MethodAttributes.Static) != 0) {
502 if ((bindingAttr & BindingFlags.Static) != 0)
505 if ((bindingAttr & BindingFlags.Instance) != 0)
512 ConstructorInfo[] result = new ConstructorInfo [l.Count];
517 public override Type GetElementType () {
518 throw not_supported ();
522 public override EventInfo GetEvent (string name, BindingFlags bindingAttr) {
524 throw new ArgumentNullException ("name");
526 throw new NotImplementedException ();
529 public override EventInfo[] GetEvents (BindingFlags bindingAttr) {
530 return new EventInfo [0];
534 public override FieldInfo GetField( string name, BindingFlags bindingAttr) {
536 throw new ArgumentNullException ("name");
538 throw new NotImplementedException ();
541 public override FieldInfo[] GetFields (BindingFlags bindingAttr) {
543 return new FieldInfo [0];
544 ArrayList l = new ArrayList ();
546 FieldAttributes mattrs;
548 foreach (FieldInfo c in fields) {
550 mattrs = c.Attributes;
551 if ((mattrs & FieldAttributes.FieldAccessMask) == FieldAttributes.Public) {
552 if ((bindingAttr & BindingFlags.Public) != 0)
555 if ((bindingAttr & BindingFlags.NonPublic) != 0)
561 if ((mattrs & FieldAttributes.Static) != 0) {
562 if ((bindingAttr & BindingFlags.Static) != 0)
565 if ((bindingAttr & BindingFlags.Instance) != 0)
572 FieldInfo[] result = new FieldInfo [l.Count];
578 public override Type GetInterface (string name, bool ignoreCase) {
580 throw new ArgumentNullException ("name");
582 throw new NotImplementedException ();
585 public override Type[] GetInterfaces () {
586 if (interfaces != null) {
587 Type[] ret = new Type [interfaces.Length];
588 interfaces.CopyTo (ret, 0);
591 return Type.EmptyTypes;
596 public override MemberInfo[] GetMembers( BindingFlags bindingAttr) {
598 throw new NotImplementedException ();
601 public override MethodInfo[] GetMethods (BindingFlags bindingAttr) {
603 return new MethodInfo [0];
604 ArrayList l = new ArrayList ();
606 MethodAttributes mattrs;
608 foreach (MethodInfo c in methods) {
610 mattrs = c.Attributes;
611 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
612 if ((bindingAttr & BindingFlags.Public) != 0)
615 if ((bindingAttr & BindingFlags.NonPublic) != 0)
621 if ((mattrs & MethodAttributes.Static) != 0) {
622 if ((bindingAttr & BindingFlags.Static) != 0)
625 if ((bindingAttr & BindingFlags.Instance) != 0)
632 MethodInfo[] result = new MethodInfo [l.Count];
638 protected override MethodInfo GetMethodImpl( string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) {
640 throw new NotImplementedException ();
644 public override Type GetNestedType( string name, BindingFlags bindingAttr) {
646 throw new ArgumentNullException ("name");
648 throw new NotImplementedException ();
651 public override Type[] GetNestedTypes (BindingFlags bindingAttr) {
653 ArrayList result = new ArrayList ();
655 if (subtypes == null)
656 return Type.EmptyTypes;
657 foreach (TypeBuilder t in subtypes) {
659 if ((t.attrs & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic) {
660 if ((bindingAttr & BindingFlags.Public) != 0)
663 if ((bindingAttr & BindingFlags.NonPublic) != 0)
670 Type[] r = new Type [result.Count];
675 public override PropertyInfo[] GetProperties( BindingFlags bindingAttr) {
676 if (properties == null)
677 return new PropertyInfo [0];
678 ArrayList l = new ArrayList ();
680 MethodAttributes mattrs;
683 foreach (PropertyInfo c in properties) {
685 accessor = c.GetGetMethod (true);
686 if (accessor == null)
687 accessor = c.GetSetMethod (true);
688 if (accessor == null)
690 mattrs = accessor.Attributes;
691 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
692 if ((bindingAttr & BindingFlags.Public) != 0)
695 if ((bindingAttr & BindingFlags.NonPublic) != 0)
701 if ((mattrs & MethodAttributes.Static) != 0) {
702 if ((bindingAttr & BindingFlags.Static) != 0)
705 if ((bindingAttr & BindingFlags.Instance) != 0)
712 PropertyInfo[] result = new PropertyInfo [l.Count];
718 protected override PropertyInfo GetPropertyImpl( string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) {
720 throw new NotImplementedException ();
723 protected override bool HasElementTypeImpl () {
724 // According to the MSDN docs, this is supported for TypeBuilders,
725 // but in reality, it is not
726 throw not_supported ();
727 // return IsArrayImpl() || IsByRefImpl() || IsPointerImpl ();
730 public override object InvokeMember( string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) {
731 throw not_supported ();
734 protected override bool IsArrayImpl () {
735 return type_is_subtype_of (this, typeof (System.Array), false);
737 protected override bool IsByRefImpl () {
741 protected override bool IsCOMObjectImpl () {
744 protected override bool IsPointerImpl () {
748 protected override bool IsPrimitiveImpl () {
752 protected override bool IsValueTypeImpl () {
753 return ((type_is_subtype_of (this, pmodule.assemblyb.corlib_value_type, false) || type_is_subtype_of (this, typeof(System.ValueType), false)) &&
754 this != pmodule.assemblyb.corlib_value_type &&
755 this != pmodule.assemblyb.corlib_enum_type);
758 public override RuntimeTypeHandle TypeHandle {
760 throw not_supported ();
764 public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
765 if (customBuilder == null)
766 throw new ArgumentNullException ("customBuilder");
768 string attrname = customBuilder.Ctor.ReflectedType.FullName;
769 if (attrname == "System.Runtime.InteropServices.StructLayoutAttribute") {
770 byte[] data = customBuilder.Data;
771 int layout_kind; /* the (stupid) ctor takes a short or an int ... */
772 layout_kind = (int)data [2];
773 layout_kind |= ((int)data [3]) << 8;
774 attrs &= ~TypeAttributes.LayoutMask;
775 switch ((LayoutKind)layout_kind) {
776 case LayoutKind.Auto:
777 attrs |= TypeAttributes.AutoLayout;
779 case LayoutKind.Explicit:
780 attrs |= TypeAttributes.ExplicitLayout;
782 case LayoutKind.Sequential:
783 attrs |= TypeAttributes.SequentialLayout;
786 // we should ignore it since it can be any value anyway...
787 throw new Exception ("Error in customattr");
789 string first_type_name = customBuilder.Ctor.GetParameters()[0].ParameterType.FullName;
791 if (first_type_name == "System.Int16")
793 int nnamed = (int)data [pos++];
794 nnamed |= ((int)data [pos++]) << 8;
795 for (int i = 0; i < nnamed; ++i) {
796 byte named_type = data [pos++];
797 byte type = data [pos++];
798 int len = CustomAttributeBuilder.decode_len (data, pos, out pos);
799 string named_name = CustomAttributeBuilder.string_from_bytes (data, pos, len);
801 /* all the fields are integers in StructLayout */
802 int value = (int)data [pos++];
803 value |= ((int)data [pos++]) << 8;
804 value |= ((int)data [pos++]) << 16;
805 value |= ((int)data [pos++]) << 24;
806 switch (named_name) {
808 switch ((CharSet)value) {
812 case CharSet.Unicode:
813 attrs |= TypeAttributes.UnicodeClass;
816 attrs |= TypeAttributes.AutoClass;
819 break; // error out...
823 packing_size = (PackingSize)value;
829 break; // error out...
833 } else if (attrname == "System.SerializableAttribute") {
834 attrs |= TypeAttributes.Serializable;
837 if (cattrs != null) {
838 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
839 cattrs.CopyTo (new_array, 0);
840 new_array [cattrs.Length] = customBuilder;
843 cattrs = new CustomAttributeBuilder [1];
844 cattrs [0] = customBuilder;
847 public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
848 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
851 public EventBuilder DefineEvent( string name, EventAttributes attributes, Type eventtype) {
852 check_name ("name", name);
853 if (eventtype == null)
854 throw new ArgumentNullException ("eventtype");
856 throw not_after_created ();
858 EventBuilder res = new EventBuilder (this, name, attributes, eventtype);
859 if (events != null) {
860 EventBuilder[] new_events = new EventBuilder [events.Length+1];
861 System.Array.Copy (events, new_events, events.Length);
862 new_events [events.Length] = res;
865 events = new EventBuilder [1];
871 static int InitializedDataCount = 0;
873 public FieldBuilder DefineInitializedData( string name, byte[] data, FieldAttributes attributes) {
874 check_name ("name", name);
876 throw new ArgumentNullException ("data");
877 if ((data.Length == 0) || (data.Length > 0x3f0000))
878 throw new ArgumentException ("data", "Data size must be > 0 and < 0x3f0000");
880 throw not_after_created ();
882 TypeBuilder datablobtype = DefineNestedType ("$ArrayType$"+InitializedDataCount.ToString(),
883 TypeAttributes.NestedPrivate|TypeAttributes.ExplicitLayout|TypeAttributes.Sealed,
884 pmodule.assemblyb.corlib_value_type, null, PackingSize.Size1, data.Length);
885 datablobtype.CreateType ();
886 FieldBuilder res = DefineField (name, datablobtype, attributes|FieldAttributes.Assembly|FieldAttributes.Static|FieldAttributes.HasFieldRVA);
887 res.SetRVAData (data);
888 InitializedDataCount++;
893 public FieldBuilder DefineUninitializedData( string name, int size, FieldAttributes attributes) {
894 check_name ("name", name);
895 if ((size <= 0) || (size > 0x3f0000))
896 throw new ArgumentException ("data", "Data size must be > 0 and < 0x3f0000");
898 throw not_after_created ();
900 throw new NotImplementedException ();
903 public TypeToken TypeToken {
905 return new TypeToken (0x02000000 | table_idx);
908 public void SetParent (Type parentType) {
909 if (parentType == null)
910 throw new ArgumentNullException ("parentType");
912 throw not_after_created ();
916 internal int get_next_table_index (object obj, int table, bool inc) {
917 return pmodule.get_next_table_index (obj, table, inc);
920 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
923 throw new NotSupportedException ("This method is not implemented for incomplete types.");
925 return created.GetInterfaceMap (interfaceType);
928 internal bool is_created {
930 return created != null;
934 private Exception not_supported ()
936 return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
939 private Exception not_after_created ()
941 return new InvalidOperationException ("Unable to change after type has been created.");
944 private void check_name (string argName, string name)
947 throw new ArgumentNullException (argName);
949 throw new ArgumentException (argName, "Empty name is not legal.");
950 if (name.IndexOf ((char)0) != -1)
951 throw new ArgumentException (argName, "Illegal name.");