2006-02-15 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / class / corlib / System.Reflection.Emit / TypeBuilder.cs
index 3a3bf8a7b1b3111f6a18c907ba1fe069daa74859..0795ea0939c56145f7cca5af3ed2d05180746b19 100644 (file)
@@ -40,10 +40,15 @@ using System.Globalization;
 using System.Collections;
 using System.Security;
 using System.Security.Permissions;
+using System.Diagnostics.SymbolStore;
 
 namespace System.Reflection.Emit {
-
-       public sealed class TypeBuilder : Type {
+#if NET_2_0
+       [ComVisible (true)]
+       [ComDefaultInterface (typeof (_TypeBuilder))]
+#endif
+       [ClassInterface (ClassInterfaceType.None)]
+       public sealed class TypeBuilder : Type, _TypeBuilder {
        #region Sync with reflection.h
        private string tname;
        private string nspace;
@@ -168,8 +173,17 @@ namespace System.Reflection.Emit {
                [MonoTODO]
                public override Type UnderlyingSystemType {
                        get {
-                               // This should return the type itself for non-enum types but 
-                               // that breaks mcs.
+
+                               // Return this as requested by Zoltan.
+                               
+                               return this;
+
+#if false
+                               // Dont know what to do with the rest, should be killed:
+                               // See bug: 75008.
+                               //
+                               ////// This should return the type itself for non-enum types but 
+                               ////// that breaks mcs.
                                if (fields != null) {
                                        foreach (FieldBuilder f in fields) {
                                                if ((f != null) && (f.Attributes & FieldAttributes.Static) == 0)
@@ -177,6 +191,7 @@ namespace System.Reflection.Emit {
                                        }
                                }
                                throw new InvalidOperationException ("Underlying type information on enumeration is not specified.");
+#endif
                        }
                }
 
@@ -196,7 +211,8 @@ namespace System.Reflection.Emit {
        
                public override Guid GUID {
                        get {
-                           throw not_supported ();
+                               check_created ();
+                               return created.GUID;
                        }
                }
 
@@ -225,8 +241,7 @@ namespace System.Reflection.Emit {
                                (action == SecurityAction.RequestRefuse))
                                throw new ArgumentException ("Request* values are not permitted", "action");
 
-                       if (is_created)
-                               throw not_after_created ();
+                       check_not_created ();
 
                        if (permissions != null) {
                                /* Check duplicate actions */
@@ -245,11 +260,13 @@ namespace System.Reflection.Emit {
                        attrs |= TypeAttributes.HasSecurity;
                }
 
+#if NET_2_0
+               [ComVisible (true)]
+#endif
                public void AddInterfaceImplementation( Type interfaceType) {
                        if (interfaceType == null)
                                throw new ArgumentNullException ("interfaceType");
-                       if (is_created)
-                               throw not_after_created ();
+                       check_not_created ();
 
                        if (interfaces != null) {
                                // Check for duplicates
@@ -272,6 +289,8 @@ namespace System.Reflection.Emit {
                                                                       CallingConventions callConvention, Type[] types,
                                                                       ParameterModifier[] modifiers)
                {
+                       check_created ();
+                       
                        if (ctors == null)
                                return null;
 
@@ -319,12 +338,16 @@ namespace System.Reflection.Emit {
                
                public override object[] GetCustomAttributes(bool inherit)
                {
-                       throw not_supported ();
+                       check_created ();
+
+                       return created.GetCustomAttributes (inherit);
                }
                
                public override object[] GetCustomAttributes(Type attributeType, bool inherit)
                {
-                       throw not_supported ();
+                       check_created ();
+
+                       return created.GetCustomAttributes (attributeType, inherit);
                }
 
                public TypeBuilder DefineNestedType (string name) {
@@ -369,6 +392,9 @@ namespace System.Reflection.Emit {
                        return res;
                }
 
+#if NET_2_0
+               [ComVisible (true)]
+#endif
                public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, Type[] interfaces) {
                        return DefineNestedType (name, attr, parent, interfaces, PackingSize.Unspecified, UnspecifiedTypeSize);
                }
@@ -381,10 +407,16 @@ namespace System.Reflection.Emit {
                        return DefineNestedType (name, attr, parent, null, packsize, UnspecifiedTypeSize);
                }
 
+#if NET_2_0
+               [ComVisible (true)]
+#endif
                public ConstructorBuilder DefineConstructor (MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes) {
                        return DefineConstructor (attributes, callingConvention, parameterTypes, null, null);
                }
 
+#if NET_2_0
+               [ComVisible (true)]
+#endif
 #if NET_2_0 || BOOTSTRAP_NET_2_0
                public
 #else
@@ -392,8 +424,7 @@ namespace System.Reflection.Emit {
 #endif
                ConstructorBuilder DefineConstructor (MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers)
                {
-                       if (is_created)
-                               throw not_after_created ();
+                       check_not_created ();
                        ConstructorBuilder cb = new ConstructorBuilder (this, attributes, callingConvention, parameterTypes, requiredCustomModifiers, optionalCustomModifiers);
                        if (ctors != null) {
                                ConstructorBuilder[] new_ctors = new ConstructorBuilder [ctors.Length+1];
@@ -407,6 +438,9 @@ namespace System.Reflection.Emit {
                        return cb;
                }
 
+#if NET_2_0
+               [ComVisible (true)]
+#endif
                public ConstructorBuilder DefineDefaultConstructor (MethodAttributes attributes)
                {
                        Type parent_type;
@@ -436,10 +470,6 @@ namespace System.Reflection.Emit {
                        return cb;
                }
 
-               public MethodBuilder DefineMethod( string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes) {
-                       return DefineMethod (name, attributes, CallingConventions.Standard, returnType, parameterTypes);
-               }
-
                private void append_method (MethodBuilder mb) {
                        if (methods != null) {
                                if (methods.Length == num_methods) {
@@ -454,6 +484,10 @@ namespace System.Reflection.Emit {
                        num_methods ++;
                }
 
+               public MethodBuilder DefineMethod( string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes) {
+                       return DefineMethod (name, attributes, CallingConventions.Standard, returnType, parameterTypes);
+               }
+
                public MethodBuilder DefineMethod( string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
                        return DefineMethod (name, attributes, callingConvention, returnType, null, null, parameterTypes, null, null);
                }
@@ -465,8 +499,7 @@ namespace System.Reflection.Emit {
 #endif
                MethodBuilder DefineMethod( string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers) {
                        check_name ("name", name);
-                       if (is_created)
-                               throw not_after_created ();
+                       check_not_created ();
                        if (IsInterface && (
                                !((attributes & MethodAttributes.Abstract) != 0) || 
                                !((attributes & MethodAttributes.Virtual) != 0)))
@@ -508,8 +541,7 @@ namespace System.Reflection.Emit {
                                throw new ArgumentException ("attributes", "PInvoke methods must be static and native and cannot be abstract.");
                        if (IsInterface)
                                throw new ArgumentException ("PInvoke methods cannot exist on interfaces.");            
-                       if (is_created)
-                               throw not_after_created ();
+                       check_not_created ();
 
                        MethodBuilder res 
                                = new MethodBuilder (
@@ -536,13 +568,22 @@ namespace System.Reflection.Emit {
                                nativeCallConv, nativeCharSet);
                }
 
+#if NET_2_0 || BOOTSTRAP_NET_2_0
+               public MethodBuilder DefineMethod (string name, MethodAttributes attributes) {
+                       return DefineMethod (name, attributes, CallingConventions.Standard);
+               }
+
+               public MethodBuilder DefineMethod (string name, MethodAttributes attributes, CallingConventions callConv) {
+                       return DefineMethod (name, attributes, callConv, null, null);
+               }
+#endif
+
                public void DefineMethodOverride( MethodInfo methodInfoBody, MethodInfo methodInfoDeclaration) {
                        if (methodInfoBody == null)
                                throw new ArgumentNullException ("methodInfoBody");
                        if (methodInfoDeclaration == null)
                                throw new ArgumentNullException ("methodInfoDeclaration");
-                       if (is_created)
-                               throw not_after_created ();
+                       check_not_created ();
 
                        if (methodInfoBody is MethodBuilder) {
                                MethodBuilder mb = (MethodBuilder)methodInfoBody;
@@ -559,12 +600,11 @@ namespace System.Reflection.Emit {
 #else
                internal
 #endif
-           FieldBuilder DefineFieldstring fieldName, Type type, Type[] requiredCustomAttributes, Type[] optionalCustomAttributes, FieldAttributes attributes) {
+           FieldBuilder DefineField (string fieldName, Type type, Type[] requiredCustomAttributes, Type[] optionalCustomAttributes, FieldAttributes attributes) {
                        check_name ("fieldName", fieldName);
                        if (type == typeof (void))
                                throw new ArgumentException ("type",  "Bad field type in defining field.");
-                       if (is_created)
-                               throw not_after_created ();
+                       check_not_created ();
 
                        FieldBuilder res = new FieldBuilder (this, fieldName, type, attributes, requiredCustomAttributes, optionalCustomAttributes);
                        if (fields != null) {
@@ -585,15 +625,23 @@ namespace System.Reflection.Emit {
                }
 
                public PropertyBuilder DefineProperty( string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes) {
+                       return DefineProperty (name, attributes, returnType, null, null, parameterTypes, null, null);
+               }
+
+#if NET_2_0
+               public 
+#else
+               internal
+#endif
+               PropertyBuilder DefineProperty (string name, PropertyAttributes attributes, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers) {
                        check_name ("name", name);
                        if (parameterTypes != null)
                                foreach (Type param in parameterTypes)
                                        if (param == null)
                                                throw new ArgumentNullException ("parameterTypes");
-                       if (is_created)
-                               throw not_after_created ();
+                       check_not_created ();
 
-                       PropertyBuilder res = new PropertyBuilder (this, name, attributes, returnType, parameterTypes);
+                       PropertyBuilder res = new PropertyBuilder (this, name, attributes, returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);
 
                        if (properties != null) {
                                PropertyBuilder[] new_properties = new PropertyBuilder [properties.Length+1];
@@ -607,6 +655,9 @@ namespace System.Reflection.Emit {
                        return res;
                }
 
+#if NET_2_0
+               [ComVisible (true)]
+#endif
                public ConstructorBuilder DefineTypeInitializer() {
                        return DefineConstructor (MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, null);
                }
@@ -626,8 +677,10 @@ namespace System.Reflection.Emit {
                
                public Type CreateType() {
                        /* handle nesting_type */
-                       if (is_created)
-                               throw not_after_created ();
+                       if (created != null)
+                               return created;
+
+                       create_generic_class ();
 
                        // Fire TypeResolve events for fields whose type is an unfinished
                        // value type.
@@ -651,6 +704,9 @@ namespace System.Reflection.Emit {
                                }
                        }
 
+                       if ((parent != null) && parent.IsSealed)
+                               throw new TypeLoadException ("Could not load type '" + FullName + "' from assembly '" + Assembly + "' because the parent type is sealed.");
+
                        if (methods != null) {
                                for (int i = 0; i < num_methods; ++i)
                                        ((MethodBuilder)(methods[i])).fixup ();
@@ -667,13 +723,35 @@ namespace System.Reflection.Emit {
                                foreach (ConstructorBuilder ctor in ctors) 
                                        ctor.fixup ();
                        }
-
+                       
                        created = create_runtime_class (this);
                        if (created != null)
                                return created;
                        return this;
                }
 
+               internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
+               {
+                       symbolWriter.OpenNamespace (this.Namespace);
+
+                       if (methods != null) {
+                               for (int i = 0; i < num_methods; ++i) {
+                                       MethodBuilder metb = (MethodBuilder) methods[i]; 
+                                       metb.GenerateDebugInfo (symbolWriter);
+                               }
+                       }
+
+                       if (ctors != null) {
+                               foreach (ConstructorBuilder ctor in ctors)
+                                       ctor.GenerateDebugInfo (symbolWriter);
+                       }
+                       
+                       symbolWriter.CloseNamespace ();
+               }
+
+#if NET_2_0
+               [ComVisible (true)]
+#endif
                public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
                {
                        if (ctors == null)
@@ -712,11 +790,13 @@ namespace System.Reflection.Emit {
                }
 
                public override Type GetElementType () { 
-                       throw not_supported ();
+                       check_created ();
+                       return created.GetElementType ();
                }
 
                public override EventInfo GetEvent (string name, BindingFlags bindingAttr) {
-                       throw not_supported ();
+                       check_created ();
+                       return created.GetEvent (name, bindingAttr);
                }
 
                /* Needed to keep signature compatibility with MS.NET */
@@ -726,9 +806,13 @@ namespace System.Reflection.Emit {
                }
 
                public override EventInfo[] GetEvents (BindingFlags bindingAttr) {
-                       // FIXME: Under MS.NET, this throws a NotImplementedException
-                       // But mcs calls this method. How can that be?
-                       return new EventInfo [0];
+                       /* FIXME: mcs calls this
+                          check_created ();
+                       */
+                       if (!is_created)
+                               return new EventInfo [0];
+                       else
+                               return created.GetEvents (bindingAttr);
                }
 
                // This is only used from MonoGenericInst.initialize().
@@ -855,7 +939,8 @@ namespace System.Reflection.Emit {
                }
 
                public override Type GetInterface (string name, bool ignoreCase) {
-                       throw not_supported ();
+                       check_created ();
+                       return created.GetInterface (name, ignoreCase);
                }
                
                public override Type[] GetInterfaces () {
@@ -870,11 +955,13 @@ namespace System.Reflection.Emit {
 
                public override MemberInfo[] GetMember (string name, MemberTypes type,
                                                                                                BindingFlags bindingAttr) {
-                       throw not_supported ();
+                       check_created ();
+                       return created.GetMember (name, type, bindingAttr);
                }
 
                public override MemberInfo[] GetMembers (BindingFlags bindingAttr) {
-                       throw not_supported ();
+                       check_created ();
+                       return created.GetMembers (bindingAttr);
                }
 
                private MethodInfo[] GetMethodsByName (string name, BindingFlags bindingAttr, bool ignoreCase, Type reflected_type) {
@@ -891,7 +978,7 @@ namespace System.Reflection.Emit {
                        }
                        else
                                candidates = methods;
-                                       
+
                        if (candidates == null)
                                return new MethodInfo [0];
 
@@ -944,9 +1031,7 @@ namespace System.Reflection.Emit {
                                                             CallingConventions callConvention,
                                                             Type[] types, ParameterModifier[] modifiers)
                {
-                       if (!is_created)
-                               /* MS.Net throws this exception if the type is unfinished... */
-                               throw not_supported ();
+                       check_created ();
 
                        bool ignoreCase = ((bindingAttr & BindingFlags.IgnoreCase) != 0);
                        MethodInfo[] methods = GetMethodsByName (name, bindingAttr, ignoreCase, this);
@@ -991,7 +1076,8 @@ namespace System.Reflection.Emit {
                }
 
                public override Type GetNestedType( string name, BindingFlags bindingAttr) {
-                       throw not_supported ();
+                       check_created ();
+                       return created.GetNestedType (name, bindingAttr);
                }
 
                public override Type[] GetNestedTypes (BindingFlags bindingAttr) {
@@ -1065,14 +1151,13 @@ namespace System.Reflection.Emit {
                }
 
                protected override bool HasElementTypeImpl () {
-                       // According to the MSDN docs, this is supported for TypeBuilders,
-                       // but in reality, it is not
-                       throw not_supported ();
-                       //                      return IsArrayImpl() || IsByRefImpl() || IsPointerImpl ();
+                       check_created ();
+                       return created.HasElementType;
                }
 
                public override object InvokeMember( string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) {
-                       throw not_supported ();
+                       check_created ();
+                       return created.InvokeMember (name, invokeAttr, binder, target, args, modifiers, culture, namedParameters);
                }
 
                protected override bool IsArrayImpl ()
@@ -1103,7 +1188,8 @@ namespace System.Reflection.Emit {
                
                public override RuntimeTypeHandle TypeHandle { 
                        get { 
-                               throw not_supported (); 
+                               check_created ();
+                               return created.TypeHandle;
                        } 
                }
 
@@ -1139,14 +1225,16 @@ namespace System.Reflection.Emit {
                                int nnamed = (int)data [pos++];
                                nnamed |= ((int)data [pos++]) << 8;
                                for (int i = 0; i < nnamed; ++i) {
-                                       byte named_type = data [pos++];
+                                       //byte named_type = data [pos++];
+                                       pos ++;
                                        byte type = data [pos++];
                                        int len;
                                        string named_name;
 
                                        if (type == 0x55) {
                                                len = CustomAttributeBuilder.decode_len (data, pos, out pos);
-                                               string named_typename = CustomAttributeBuilder.string_from_bytes (data, pos, len);
+                                               //string named_typename = 
+                                               CustomAttributeBuilder.string_from_bytes (data, pos, len);
                                                pos += len;
                                                // FIXME: Check that 'named_type' and 'named_typename' match, etc.
                                                //        See related code/FIXME in mono/mono/metadata/reflection.c
@@ -1165,11 +1253,14 @@ namespace System.Reflection.Emit {
                                                switch ((CharSet)value) {
                                                case CharSet.None:
                                                case CharSet.Ansi:
+                                                       attrs &= ~(TypeAttributes.UnicodeClass | TypeAttributes.AutoClass);
                                                        break;
                                                case CharSet.Unicode:
+                                                       attrs &= ~TypeAttributes.AutoClass;
                                                        attrs |= TypeAttributes.UnicodeClass;
                                                        break;
                                                case CharSet.Auto:
+                                                       attrs &= ~TypeAttributes.UnicodeClass;
                                                        attrs |= TypeAttributes.AutoClass;
                                                        break;
                                                default:
@@ -1187,10 +1278,19 @@ namespace System.Reflection.Emit {
                                        }
                                }
                                return;
+#if NET_2_0
+                       } else if (attrname == "System.Runtime.CompilerServices.SpecialNameAttribute") {
+                               attrs |= TypeAttributes.SpecialName;
+                               return;
+#endif
                        } else if (attrname == "System.SerializableAttribute") {
                                attrs |= TypeAttributes.Serializable;
                                return;
+                       } else if (attrname == "System.Runtime.InteropServices.ComImportAttribute") {
+                               attrs |= TypeAttributes.Import;
+                               return;
                        }
+
                        if (cattrs != null) {
                                CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
                                cattrs.CopyTo (new_array, 0);
@@ -1201,6 +1301,10 @@ namespace System.Reflection.Emit {
                                cattrs [0] = customBuilder;
                        }
                }
+
+#if NET_2_0
+               [ComVisible (true)]
+#endif
                public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
                        SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
                }
@@ -1209,8 +1313,7 @@ namespace System.Reflection.Emit {
                        check_name ("name", name);
                        if (eventtype == null)
                                throw new ArgumentNullException ("eventtype");
-                       if (is_created)
-                               throw not_after_created ();
+                       check_not_created ();
 
                        EventBuilder res = new EventBuilder (this, name, attributes, eventtype);
                        if (events != null) {
@@ -1243,8 +1346,7 @@ namespace System.Reflection.Emit {
                        check_name ("name", name);
                        if ((size <= 0) || (size > 0x3f0000))
                                throw new ArgumentException ("size", "Data size must be > 0 and < 0x3f0000");
-                       if (is_created)
-                               throw not_after_created ();
+                       check_not_created ();
 
                        string s = "$ArrayType$"+UnmanagedDataCount.ToString();
                        UnmanagedDataCount++;
@@ -1263,8 +1365,7 @@ namespace System.Reflection.Emit {
                public void SetParent (Type parentType) {
                        if (parentType == null)
                                throw new ArgumentNullException ("parentType");
-                       if (is_created)
-                               throw not_after_created ();
+                       check_not_created ();
 
                        parent = parentType;
                        // will just set the parent-related bits if called a second time
@@ -1274,6 +1375,9 @@ namespace System.Reflection.Emit {
                        return pmodule.get_next_table_index (obj, table, inc);
                }
 
+#if NET_2_0
+               [ComVisible (true)]
+#endif
                public override InterfaceMapping GetInterfaceMap (Type interfaceType)
                {
                        if (created == null)
@@ -1293,19 +1397,26 @@ namespace System.Reflection.Emit {
                        return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
                }
 
-               private Exception not_after_created ()
+               private void check_not_created ()
                {
-                       return new InvalidOperationException ("Unable to change after type has been created.");
+                       if (is_created)
+                               throw new InvalidOperationException ("Unable to change after type has been created.");
+               }
+
+               private void check_created ()
+               {
+                       if (!is_created)
+                               throw not_supported ();
                }
 
                private void check_name (string argName, string name)
                {
                        if (name == null)
                                throw new ArgumentNullException (argName);
-                       if (name == "")
-                               throw new ArgumentException (argName, "Empty name is not legal.");
+                       if (name.Length == 0)
+                               throw new ArgumentException ("Empty name is not legal", argName);
                        if (name.IndexOf ((char)0) != -1)
-                               throw new ArgumentException (argName, "Illegal name.");
+                               throw new ArgumentException ("Illegal name", argName);
                }
 
                public override String ToString ()
@@ -1319,12 +1430,36 @@ namespace System.Reflection.Emit {
                        return base.IsAssignableFrom (c);
                }
 
+#if NET_2_0
+               [ComVisible (true)]
+#endif
                [MonoTODO]
                public override bool IsSubclassOf (Type c)
                {
                        return base.IsSubclassOf (c);
                }
 
+               [MonoTODO ("arrays")]
+               internal bool IsAssignableTo (Type c)
+               {
+                       if (c == this)
+                               return true;
+
+                       if (c.IsInterface) {
+                               if (interfaces == null)
+                                       return false;
+                               foreach (Type t in interfaces)
+                                       if (c.IsAssignableFrom (t))
+                                               return true;
+                               return false;
+                       }
+
+                       if (parent == null)
+                               return c == typeof (object);
+                       else
+                               return c.IsAssignableFrom (parent);
+               }
+
 #if NET_2_0 || BOOTSTRAP_NET_2_0
                public bool IsCreated () {
                        return is_created;
@@ -1345,12 +1480,6 @@ namespace System.Reflection.Emit {
                        return base.GetGenericTypeDefinition ();
                }
 
-               public override bool HasGenericArguments {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-               }
-
                public override bool ContainsGenericParameters {
                        get {
                                return generic_params != null;
@@ -1362,19 +1491,29 @@ namespace System.Reflection.Emit {
                        get;
                }
 
+               public override bool IsGenericTypeDefinition {
+                       get {
+                               return generic_params != null;
+                       }
+               }
+
+               public override bool IsGenericType {
+                       get { return IsGenericTypeDefinition; }
+               }
+
                public override int GenericParameterPosition {
                        get {
                                throw new NotImplementedException ();
                        }
                }
 
-               public override MethodInfo DeclaringMethod {
+               public override MethodBase DeclaringMethod {
                        get {
                                throw new NotImplementedException ();
                        }
                }
 
-               public GenericTypeParameterBuilder[] DefineGenericParameters (string[] names)
+               public GenericTypeParameterBuilder[] DefineGenericParameters (params string[] names)
                {
                        setup_generic_class ();
 
@@ -1386,10 +1525,52 @@ namespace System.Reflection.Emit {
                        return generic_params;
                }
 
-               public MethodBuilder DefineGenericMethod (string name, MethodAttributes attributes)
-               {
-                       return DefineMethod (name, attributes, CallingConventions.Standard, null, null);
-               }
+                public static ConstructorInfo GetConstructor (Type instanciated, ConstructorInfo ctor)
+                {
+                       ConstructorInfo res = instanciated.GetConstructor (ctor);
+                       if (res == null)
+                               throw new System.Exception ("constructor not found");
+                       else
+                               return res;
+                }
+
+                public static MethodInfo GetMethod (Type instanciated, MethodInfo meth)
+                {
+                       MethodInfo res = instanciated.GetMethod (meth);
+                       if (res == null)
+                               throw new System.Exception ("method not found");
+                       else
+                               return res;
+                }
+
+                public static FieldInfo GetField (Type instanciated, FieldInfo fld)
+                {
+                       FieldInfo res = instanciated.GetField (fld);
+                       if (res == null)
+                               throw new System.Exception ("field not found");
+                       else
+                               return res;
+                }
 #endif
+
+                void _TypeBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
+                {
+                        throw new NotImplementedException ();
+                }
+
+                void _TypeBuilder.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
+                {
+                        throw new NotImplementedException ();
+                }
+
+                void _TypeBuilder.GetTypeInfoCount (out uint pcTInfo)
+                {
+                        throw new NotImplementedException ();
+                }
+
+                void _TypeBuilder.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
+                {
+                        throw new NotImplementedException ();
+                }
        }
 }