Merge pull request #1898 from alexanderkyte/debugger_variable_reflection
[mono.git] / mcs / class / corlib / System.Reflection.Emit / TypeBuilder.cs
index 64b5bf4bde5f15acdb540f1a7eca630bb05606d6..edf6d58852807e250a372202a96240db1ef8aa41 100644 (file)
@@ -44,9 +44,6 @@ using System.Security;
 using System.Security.Permissions;
 using System.Diagnostics.SymbolStore;
 
-#if !NET_4_5
-using TypeInfo = System.Type;
-#endif
 
 namespace System.Reflection.Emit
 {
@@ -356,7 +353,7 @@ namespace System.Reflection.Emit
                                        }
                                }
                                if (binder == null)
-                                       binder = Binder.DefaultBinder;
+                                       binder = DefaultBinder;
                                return (ConstructorInfo) binder.SelectMethod (bindingAttr, match,
                                                                                                                          types, modifiers);
                        }
@@ -683,12 +680,10 @@ namespace System.Reflection.Emit
                        return DefineProperty (name, attributes, 0, returnType, null, null, parameterTypes, null, null);
                }
                
-#if NET_4_0
                public PropertyBuilder DefineProperty (string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
                {
                        return DefineProperty (name, attributes, callingConvention, returnType , null, null, parameterTypes, null, null);
                }       
-#endif
 
                public PropertyBuilder DefineProperty (string name, PropertyAttributes attributes, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
                {
@@ -757,9 +752,7 @@ namespace System.Reflection.Emit
                        return CreateTypeInfo ();
                }
                
-#if NET_4_5
                public
-#endif
                TypeInfo CreateTypeInfo ()
                {
                        /* handle nesting_type */
@@ -808,6 +801,12 @@ namespace System.Reflection.Emit
 
                        if (parent == pmodule.assemblyb.corlib_enum_type && methods != null)
                                throw new TypeLoadException ("Could not load type '" + FullName + "' from assembly '" + Assembly + "' because it is an enum with methods.");
+                       if (interfaces != null) {
+                               foreach (var iface in interfaces) {
+                                       if (iface.IsNestedPrivate && iface.Assembly != Assembly)
+                                               throw new TypeLoadException ("Could not load type '" + FullName + "' from assembly '" + Assembly + "' because it is implements the inaccessible interface '" + iface.FullName + "'.");
+                               }
+                       }
 
                        if (methods != null) {
                                bool is_concrete = !IsAbstract;
@@ -915,6 +914,7 @@ namespace System.Reflection.Emit
                /* Needed to keep signature compatibility with MS.NET */
                public override EventInfo[] GetEvents ()
                {
+                       const BindingFlags DefaultBindingFlags = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
                        return GetEvents (DefaultBindingFlags);
                }
 
@@ -1193,46 +1193,10 @@ namespace System.Reflection.Emit
                {
                        check_created ();
 
-                       bool ignoreCase = ((bindingAttr & BindingFlags.IgnoreCase) != 0);
-                       MethodInfo[] methods = GetMethodsByName (name, bindingAttr, ignoreCase, this);
-                       MethodInfo found = null;
-                       MethodBase[] match;
-                       int typesLen = (types != null) ? types.Length : 0;
-                       int count = 0;
-                       
-                       foreach (MethodInfo m in methods) {
-                               // Under MS.NET, Standard|HasThis matches Standard...
-                               if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
-                                       continue;
-                               found = m;
-                               count++;
-                       }
+                       if (types == null)
+                               return created.GetMethod (name, bindingAttr);
 
-                       if (count == 0)
-                               return null;
-                       
-                       if (count == 1 && typesLen == 0) 
-                               return found;
-
-                       match = new MethodBase [count];
-                       if (count == 1)
-                               match [0] = found;
-                       else {
-                               count = 0;
-                               foreach (MethodInfo m in methods) {
-                                       if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
-                                               continue;
-                                       match [count++] = m;
-                               }
-                       }
-                       
-                       if (types == null) 
-                               return (MethodInfo) Binder.FindMostDerivedMatch (match);
-
-                       if (binder == null)
-                               binder = Binder.DefaultBinder;
-                       
-                       return (MethodInfo)binder.SelectMethod (bindingAttr, match, types, modifiers);
+                       return created.GetMethod (name, bindingAttr, binder, callConvention, types, modifiers);
                }
 
                public override Type GetNestedType (string name, BindingFlags bindingAttr)
@@ -1900,19 +1864,6 @@ namespace System.Reflection.Emit
                                return res;
                }
 
-               internal TypeCode GetTypeCodeInternal () {
-                       if (parent == pmodule.assemblyb.corlib_enum_type) {
-                               for (int i = 0; i < num_fields; ++i) {
-                                       FieldBuilder f = fields [i];
-                                       if (!f.IsStatic)
-                                               return Type.GetTypeCode (f.FieldType);
-                               }
-                               throw new InvalidOperationException ("Enum basetype field not defined");
-                       } else {
-                               return Type.GetTypeCodeInternal (this);
-                       }
-               }
-
 
                void _TypeBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
                {
@@ -1940,7 +1891,6 @@ namespace System.Reflection.Emit
                        }
                }
 
-#if NET_4_5
                public override bool IsConstructedGenericType {
                        get { return false; }
                }
@@ -1949,7 +1899,6 @@ namespace System.Reflection.Emit
                {
                        return base.IsAssignableFrom (typeInfo);
                }
-#endif
        }
 }
 #endif