2006-02-15 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / class / corlib / System.Reflection.Emit / TypeBuilder.cs
index 0aa9ba44c02e69067ef7bf263fd4c41ff283027f..0795ea0939c56145f7cca5af3ed2d05180746b19 100644 (file)
@@ -45,10 +45,10 @@ using System.Diagnostics.SymbolStore;
 namespace System.Reflection.Emit {
 #if NET_2_0
        [ComVisible (true)]
-       [ClassInterfaceAttribute (ClassInterfaceType.None)]
-       [ComDefaultInterfaceAttribute (typeof (_TypeBuilder))]
+       [ComDefaultInterface (typeof (_TypeBuilder))]
 #endif
-       public sealed class TypeBuilder : Type {
+       [ClassInterface (ClassInterfaceType.None)]
+       public sealed class TypeBuilder : Type, _TypeBuilder {
        #region Sync with reflection.h
        private string tname;
        private string nspace;
@@ -568,7 +568,7 @@ namespace System.Reflection.Emit {
                                nativeCallConv, nativeCharSet);
                }
 
-#if NET_2_0
+#if NET_2_0 || BOOTSTRAP_NET_2_0
                public MethodBuilder DefineMethod (string name, MethodAttributes attributes) {
                        return DefineMethod (name, attributes, CallingConventions.Standard);
                }
@@ -680,6 +680,8 @@ namespace System.Reflection.Emit {
                        if (created != null)
                                return created;
 
+                       create_generic_class ();
+
                        // Fire TypeResolve events for fields whose type is an unfinished
                        // value type.
                        if (fields != null) {
@@ -702,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 ();
@@ -973,7 +978,7 @@ namespace System.Reflection.Emit {
                        }
                        else
                                candidates = methods;
-                                       
+
                        if (candidates == null)
                                return new MethodInfo [0];
 
@@ -1273,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);
@@ -1466,21 +1480,25 @@ namespace System.Reflection.Emit {
                        return base.GetGenericTypeDefinition ();
                }
 
-               public override bool HasGenericArguments {
+               public override bool ContainsGenericParameters {
                        get {
                                return generic_params != null;
                        }
                }
 
-               public override bool ContainsGenericParameters {
+               public extern override bool IsGenericParameter {
+                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
+                       get;
+               }
+
+               public override bool IsGenericTypeDefinition {
                        get {
                                return generic_params != null;
                        }
                }
 
-               public extern override bool IsGenericParameter {
-                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
-                       get;
+               public override bool IsGenericType {
+                       get { return IsGenericTypeDefinition; }
                }
 
                public override int GenericParameterPosition {
@@ -1489,7 +1507,7 @@ namespace System.Reflection.Emit {
                        }
                }
 
-               public override MethodInfo DeclaringMethod {
+               public override MethodBase DeclaringMethod {
                        get {
                                throw new NotImplementedException ();
                        }
@@ -1507,11 +1525,6 @@ 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);
@@ -1539,5 +1552,25 @@ namespace System.Reflection.Emit {
                                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 ();
+                }
        }
 }