[corlib] Type from reference sources
authorMarek Safar <marek.safar@gmail.com>
Wed, 11 Mar 2015 09:08:07 +0000 (10:08 +0100)
committerMarek Safar <marek.safar@gmail.com>
Wed, 11 Mar 2015 09:09:11 +0000 (10:09 +0100)
22 files changed:
external/referencesource
mcs/class/corlib/ReferenceSources/ReflectionOnlyType.cs [deleted file]
mcs/class/corlib/ReferenceSources/RuntimeType.cs [new file with mode: 0644]
mcs/class/corlib/ReferenceSources/TypeNameParser.cs [new file with mode: 0644]
mcs/class/corlib/System.Reflection.Emit/GenericTypeParameterBuilder.cs
mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
mcs/class/corlib/System.Reflection/CustomAttributeData.cs
mcs/class/corlib/System.Reflection/MonoEvent.cs
mcs/class/corlib/System.Reflection/MonoField.cs
mcs/class/corlib/System.Reflection/MonoMethod.cs
mcs/class/corlib/System.Reflection/MonoModule.cs
mcs/class/corlib/System.Reflection/MonoProperty.cs
mcs/class/corlib/System/Array.cs
mcs/class/corlib/System/MonoCustomAttrs.cs
mcs/class/corlib/System/MonoType.cs
mcs/class/corlib/System/RuntimeTypeHandle.cs
mcs/class/corlib/System/Type.cs [deleted file]
mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs
mcs/class/corlib/Test/System/TypeTest.cs
mcs/class/corlib/corlib.dll.sources
mono/metadata/icall-def.h
mono/metadata/icall.c

index 4bb7900e7905930505b93124c2ab144936903ba4..7e80630117b1306dc45e1c2714ebc1f9ee7f5f82 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 4bb7900e7905930505b93124c2ab144936903ba4
+Subproject commit 7e80630117b1306dc45e1c2714ebc1f9ee7f5f82
diff --git a/mcs/class/corlib/ReferenceSources/ReflectionOnlyType.cs b/mcs/class/corlib/ReferenceSources/ReflectionOnlyType.cs
deleted file mode 100644 (file)
index 532c961..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-namespace System
-{
-    // this is the introspection only type. This type overrides all the functions with runtime semantics
-    // and throws an exception.
-    // The idea behind this type is that it relieves RuntimeType from doing honerous checks about ReflectionOnly
-    // context.
-    // This type should not derive from RuntimeType but it's doing so for convinience.
-    // That should not present a security threat though it is risky as a direct call to one of the base method
-    // method (RuntimeType) and an instance of this type will work around the reason to have this type in the 
-    // first place. However given RuntimeType is not public all its methods are protected and require full trust
-    // to be accessed
-    [Serializable]
-    internal class ReflectionOnlyType : MonoType {
-
-        private ReflectionOnlyType() : base (null)
-        {}
-
-        // always throw
-        public override RuntimeTypeHandle TypeHandle 
-        {
-            get 
-            {
-                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAllowedInReflectionOnly"));
-            }
-        }
-
-    }
-}
\ No newline at end of file
diff --git a/mcs/class/corlib/ReferenceSources/RuntimeType.cs b/mcs/class/corlib/ReferenceSources/RuntimeType.cs
new file mode 100644 (file)
index 0000000..e0f48d3
--- /dev/null
@@ -0,0 +1,653 @@
+//
+// RuntimeType.cs
+//
+// Authors:
+//     Marek Safar  <marek.safar@gmail.com>
+//
+// Copyright (C) 2015 Xamarin Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using System.Globalization;
+#if MONO_COM
+using System.Reflection.Emit;
+#endif
+using System.Diagnostics.Contracts;
+using System.Security;
+
+namespace System
+{
+       partial class RuntimeType
+       {
+               internal virtual MonoCMethod GetDefaultConstructor ()
+               {
+                       // TODO: Requires MonoType
+                       throw new NotSupportedException ();
+               }
+
+               string GetDefaultMemberName ()
+               {
+                       object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
+                       return att.Length != 0 ? ((DefaultMemberAttribute) att [0]).MemberName : null;
+               }
+
+               internal Object CreateInstanceSlow(bool publicOnly, bool skipCheckThis, bool fillCache, ref StackCrawlMark stackMark)
+               {
+                       bool bNeedSecurityCheck = true;
+                       bool bCanBeCached = false;
+                       bool bSecurityCheckOff = false;
+
+                       if (!skipCheckThis)
+                               CreateInstanceCheckThis();
+
+                       if (!fillCache)
+                               bSecurityCheckOff = true;
+
+                       return CreateInstanceMono (!publicOnly);
+               }
+
+               object CreateInstanceMono (bool nonPublic)
+               {
+                       var ctor = GetDefaultConstructor ();
+                       if (!nonPublic && ctor != null && !ctor.IsPublic) {
+                               ctor = null;
+                       }
+
+                       if (ctor == null) {
+                               Type elementType = this.GetRootElementType();
+                               if (ReferenceEquals (elementType, typeof (TypedReference)) || ReferenceEquals (elementType, typeof (RuntimeArgumentHandle)))
+                                       throw new NotSupportedException (Environment.GetResourceString ("NotSupported_ContainsStackPtr"));
+
+                               if (IsValueType)
+                                       return CreateInstanceInternal (this);
+
+                               throw new MissingMethodException (Locale.GetText ("Default constructor not found for type " + FullName));
+                       }
+
+                       // TODO: .net does more checks in unmanaged land in RuntimeTypeHandle::CreateInstance
+                       if (IsAbstract) {
+                               throw new MissingMethodException (Locale.GetText ("Cannot create an abstract class '{0}'.", FullName));
+                       }
+
+                       return ctor.InternalInvoke (null, null);
+               }
+
+               internal Object CheckValue (Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
+               {
+                       bool failed = false;
+                       var res = TryConvertToType (value, ref failed);
+                       if (!failed)
+                               return res;
+
+                       if ((invokeAttr & BindingFlags.ExactBinding) == BindingFlags.ExactBinding)
+                               throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Arg_ObjObjEx"), value.GetType(), this));
+
+                       if (binder != null && binder != Type.DefaultBinder)
+                               return binder.ChangeType (value, this, culture);
+
+                       throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Arg_ObjObjEx"), value.GetType(), this));
+               }
+
+               object TryConvertToType (object value, ref bool failed)
+               {
+                       if (IsInstanceOfType (value)) {
+                               return value;
+                       }
+
+                       if (IsByRef) {
+                               var elementType = GetElementType ();
+                               if (value == null || elementType.IsInstanceOfType (value)) {
+                                       return value;
+                               }
+                       }
+
+                       if (value == null)
+                               return value;
+
+                       if (IsEnum) {
+                               var type = Enum.GetUnderlyingType (this);
+                               if (type == value.GetType ())
+                                       return value;
+                               var res = IsConvertibleToPrimitiveType (value, this);
+                               if (res != null)
+                                       return res;
+                       } else if (IsPrimitive) {
+                               var res = IsConvertibleToPrimitiveType (value, this);
+                               if (res != null)
+                                       return res;
+                       } else if (IsPointer) {
+                               var vtype = value.GetType ();
+                               if (vtype == typeof (IntPtr) || vtype == typeof (UIntPtr))
+                                       return value;
+                       }
+
+                       failed = true;
+                       return null;
+               }
+
+               // Binder uses some incompatible conversion rules. For example
+               // int value cannot be used with decimal parameter but in other
+               // ways it's more flexible than normal convertor, for example
+               // long value can be used with int based enum
+               static object IsConvertibleToPrimitiveType (object value, Type targetType)
+               {
+                       var type = value.GetType ();
+                       if (type.IsEnum) {
+                               type = Enum.GetUnderlyingType (type);
+                               if (type == targetType)
+                                       return value;
+                       }
+
+                       var from = Type.GetTypeCode (type);
+                       var to = Type.GetTypeCode (targetType);
+
+                       switch (to) {
+                               case TypeCode.Char:
+                                       switch (from) {
+                                               case TypeCode.Byte:
+                                                       return (Char) (Byte) value;
+                                               case TypeCode.UInt16:
+                                                       return value;
+                                       }
+                                       break;
+                               case TypeCode.Int16:
+                                       switch (from) {
+                                               case TypeCode.Byte:
+                                                       return (Int16) (Byte) value;
+                                               case TypeCode.SByte:
+                                                       return (Int16) (SByte) value;
+                                       }
+                                       break;
+                               case TypeCode.UInt16:
+                                       switch (from) {
+                                               case TypeCode.Byte:
+                                                       return (UInt16) (Byte) value;
+                                               case TypeCode.Char:
+                                                       return value;
+                                       }
+                                       break;
+                               case TypeCode.Int32:
+                                       switch (from) {
+                                               case TypeCode.Byte:
+                                                       return (Int32) (Byte) value;
+                                               case TypeCode.SByte:
+                                                       return (Int32) (SByte) value;
+                                               case TypeCode.Char:
+                                                       return (Int32) (Char) value;
+                                               case TypeCode.Int16:
+                                                       return (Int32) (Int16) value;
+                                               case TypeCode.UInt16:
+                                                       return (Int32) (UInt16) value;
+                                       }
+                                       break;
+                               case TypeCode.UInt32:
+                                       switch (from) {
+                                               case TypeCode.Byte:
+                                                       return (UInt32) (Byte) value;
+                                               case TypeCode.Char:
+                                                       return (UInt32) (Char) value;
+                                               case TypeCode.UInt16:
+                                                       return (UInt32) (UInt16) value;
+                                       }
+                                       break;
+                               case TypeCode.Int64:
+                                       switch (from) {
+                                               case TypeCode.Byte:
+                                                       return (Int64) (Byte) value;
+                                               case TypeCode.SByte:
+                                                       return (Int64) (SByte) value;
+                                               case TypeCode.Int16:
+                                                       return (Int64) (Int16) value;
+                                               case TypeCode.Char:
+                                                       return (Int64) (Char) value;
+                                               case TypeCode.UInt16:
+                                                       return (Int64) (UInt16) value;
+                                               case TypeCode.Int32:
+                                                       return (Int64) (Int32) value;
+                                               case TypeCode.UInt32:
+                                                       return (Int64) (UInt32) value;
+                                       }
+                                       break;
+                               case TypeCode.UInt64:
+                                       switch (from) {
+                                               case TypeCode.Byte:
+                                                       return (UInt64) (Byte) value;
+                                               case TypeCode.Char:
+                                                       return (UInt64) (Char) value;
+                                               case TypeCode.UInt16:
+                                                       return (UInt64) (UInt16) value;
+                                               case TypeCode.UInt32:
+                                                       return (UInt64) (UInt32) value;
+                                       }
+                                       break;
+                               case TypeCode.Single:
+                                       switch (from) {
+                                               case TypeCode.Byte:
+                                                       return (Single) (Byte) value;
+                                               case TypeCode.SByte:
+                                                       return (Single) (SByte) value;
+                                               case TypeCode.Int16:
+                                                       return (Single) (Int16) value;
+                                               case TypeCode.Char:
+                                                       return (Single) (Char) value;
+                                               case TypeCode.UInt16:
+                                                       return (Single) (UInt16) value;
+                                               case TypeCode.Int32:
+                                                       return (Single) (Int32) value;
+                                               case TypeCode.UInt32:
+                                                       return (Single) (UInt32) value;
+                                               case TypeCode.Int64:
+                                                       return (Single) (Int64) value;
+                                               case TypeCode.UInt64:
+                                                       return (Single) (UInt64) value;
+                                       }
+                                       break;
+                               case TypeCode.Double:
+                                       switch (from) {
+                                               case TypeCode.Byte:
+                                                       return (Double) (Byte) value;
+                                               case TypeCode.SByte:
+                                                       return (Double) (SByte) value;
+                                               case TypeCode.Char:
+                                                       return (Double) (Char) value;
+                                               case TypeCode.Int16:
+                                                       return (Double) (Int16) value;
+                                               case TypeCode.UInt16:
+                                                       return (Double) (UInt16) value;
+                                               case TypeCode.Int32:
+                                                       return (Double) (Int32) value;
+                                               case TypeCode.UInt32:
+                                                       return (Double) (UInt32) value;
+                                               case TypeCode.Int64:
+                                                       return (Double) (Int64) value;
+                                               case TypeCode.UInt64:
+                                                       return (Double) (UInt64) value;
+                                               case TypeCode.Single:
+                                                       return (Double) (Single) value;
+                                       }
+                                       break;
+                       }
+
+                       // Everything else is rejected
+                       return null;
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern Type make_array_type (int rank);
+
+               public override Type MakeArrayType ()
+               {
+                       return make_array_type (0);
+               }
+
+               public override Type MakeArrayType (int rank)
+               {
+                       if (rank < 1 || rank > 255)
+                               throw new IndexOutOfRangeException ();
+                       return make_array_type (rank);
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern Type make_byref_type ();
+
+               public override Type MakeByRefType ()
+               {
+                       if (IsByRef)
+                               throw new TypeLoadException ("Can not call MakeByRefType on a ByRef type");
+                       return make_byref_type ();
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               static extern Type MakePointerType (Type type);
+
+               public override Type MakePointerType ()
+               {
+                       return MakePointerType (this);
+               }
+
+               public override StructLayoutAttribute StructLayoutAttribute {
+                       get {
+                               return GetStructLayoutAttribute ();
+                       }
+               }
+
+               public override bool ContainsGenericParameters {
+                       get {
+                               if (IsGenericParameter)
+                                       return true;
+
+                               if (IsGenericType) {
+                                       foreach (Type arg in GetGenericArguments ())
+                                               if (arg.ContainsGenericParameters)
+                                                       return true;
+                               }
+
+                               if (HasElementType)
+                                       return GetElementType ().ContainsGenericParameters;
+
+                               return false;
+                       }
+               }
+
+               public override Type[] GetGenericParameterConstraints()
+               {
+                       if (!IsGenericParameter)
+                               throw new InvalidOperationException(Environment.GetResourceString("Arg_NotGenericParameter"));
+                       Contract.EndContractBlock();
+
+                       Type[] constraints = GetGenericParameterConstraints_impl ();
+
+                       if (constraints == null)
+                               constraints = EmptyArray<Type>.Value;
+
+                       return constraints;
+               }
+
+               public override Type MakeGenericType (params Type[] typeArguments)
+               {
+                       if (IsUserType)
+                               throw new NotSupportedException ();
+                       if (!IsGenericTypeDefinition)
+                               throw new InvalidOperationException ("not a generic type definition");
+                       if (typeArguments == null)
+                               throw new ArgumentNullException ("typeArguments");
+                       if (GetGenericArguments().Length != typeArguments.Length)
+                               throw new ArgumentException (String.Format ("The type or method has {0} generic parameter(s) but {1} generic argument(s) where provided. A generic argument must be provided for each generic parameter.", GetGenericArguments ().Length, typeArguments.Length), "typeArguments");
+
+                       bool hasUserType = false;
+
+                       Type[] systemTypes = new Type[typeArguments.Length];
+                       for (int i = 0; i < typeArguments.Length; ++i) {
+                               Type t = typeArguments [i];
+                               if (t == null)
+                                       throw new ArgumentNullException ("typeArguments");
+
+                               if (!(t is MonoType))
+                                       hasUserType = true;
+                               systemTypes [i] = t;
+                       }
+
+                       if (hasUserType) {
+#if FULL_AOT_RUNTIME
+                               throw new NotSupportedException ("User types are not supported under full aot");
+#else
+                               return new MonoGenericClass (this, typeArguments);
+#endif
+                       }
+
+                       Type res = MakeGenericType (this, systemTypes);
+                       if (res == null)
+                               throw new TypeLoadException ();
+                       return res;
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               static extern Type MakeGenericType (Type gt, Type [] types);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern RuntimeMethodInfo[] GetMethodsByName (string name, BindingFlags bindingAttr, bool ignoreCase, Type reflected_type);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern RuntimePropertyInfo[] GetPropertiesByName (string name, BindingFlags bindingAttr, bool icase, Type reflected_type);              
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern RuntimeConstructorInfo[] GetConstructors_internal (BindingFlags bindingAttr, Type reflected_type);
+
+               public override InterfaceMapping GetInterfaceMap (Type ifaceType)
+               {
+                       if (IsGenericParameter)
+                               throw new InvalidOperationException(Environment.GetResourceString("Arg_GenericParameter"));
+               
+                       if ((object)ifaceType == null)
+                               throw new ArgumentNullException("ifaceType");
+                       Contract.EndContractBlock();
+
+                       RuntimeType ifaceRtType = ifaceType as RuntimeType;
+
+                       if (ifaceRtType == null)
+                               throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "ifaceType");
+
+                       InterfaceMapping res;
+                       if (!ifaceType.IsInterface)
+                               throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "ifaceType");
+                       if (IsInterface)
+                               throw new ArgumentException ("'this' type cannot be an interface itself");
+                       res.TargetType = this;
+                       res.InterfaceType = ifaceType;
+                       GetInterfaceMapData (this, ifaceType, out res.TargetMethods, out res.InterfaceMethods);
+                       if (res.TargetMethods == null)
+                               throw new ArgumentException (Locale.GetText ("Interface not found"), "ifaceType");
+
+                       return res;
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);                
+
+               public override Guid GUID {
+                       get {
+                               object[] att = GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), true);
+                               if (att.Length == 0)
+                                       return Guid.Empty;
+                               return new Guid(((System.Runtime.InteropServices.GuidAttribute)att[0]).Value);
+                       }
+               }
+
+               StructLayoutAttribute GetStructLayoutAttribute ()
+               {
+                       LayoutKind kind;
+
+                       if (IsLayoutSequential)
+                               kind = LayoutKind.Sequential;
+                       else if (IsExplicitLayout)
+                               kind = LayoutKind.Explicit;
+                       else
+                               kind = LayoutKind.Auto;
+
+                       StructLayoutAttribute attr = new StructLayoutAttribute (kind);
+
+                       if (IsUnicodeClass)
+                               attr.CharSet = CharSet.Unicode;
+                       else if (IsAnsiClass)
+                               attr.CharSet = CharSet.Ansi;
+                       else
+                               attr.CharSet = CharSet.Auto;
+
+                       if (kind != LayoutKind.Auto) {
+                               int packing;
+                               GetPacking (out packing, out attr.Size);
+                               // 0 means no data provided, we end up with default value
+                               if (packing != 0)
+                                       attr.Pack = packing;
+                       }
+
+                       return attr;
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern void GetPacking (out int packing, out int size);
+
+#if MONO_COM
+               private static Dictionary<Guid, Type> clsid_types;
+               private static AssemblyBuilder clsid_assemblybuilder;
+#endif
+
+               internal static Type GetTypeFromCLSIDImpl(Guid clsid, String server, bool throwOnError)
+               {
+#if MONO_COM
+                       Type result;
+
+                       if (clsid_types == null)
+                       {
+                               Dictionary<Guid, Type> new_clsid_types = new Dictionary<Guid, Type> ();
+                               Interlocked.CompareExchange<Dictionary<Guid, Type>>(
+                                       ref clsid_types, new_clsid_types, null);
+                       }
+
+                       lock (clsid_types) {
+                               if (clsid_types.TryGetValue(clsid, out result))
+                                       return result;
+
+                               if (clsid_assemblybuilder == null)
+                               {
+                                       AssemblyName assemblyname = new AssemblyName ();
+                                       assemblyname.Name = "GetTypeFromCLSIDDummyAssembly";
+                                       clsid_assemblybuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                               assemblyname, AssemblyBuilderAccess.Run);
+                               }
+                               ModuleBuilder modulebuilder = clsid_assemblybuilder.DefineDynamicModule (
+                                       clsid.ToString ());
+
+                               TypeBuilder typebuilder = modulebuilder.DefineType ("System.__ComObject",
+                                       TypeAttributes.Public | TypeAttributes.Class, typeof(System.__ComObject));
+
+                               Type[] guidattrtypes = new Type[] { typeof(string) };
+
+                               CustomAttributeBuilder customattr = new CustomAttributeBuilder (
+                                       typeof(GuidAttribute).GetConstructor (guidattrtypes),
+                                       new object[] { clsid.ToString () });
+
+                               typebuilder.SetCustomAttribute (customattr);
+
+                               customattr = new CustomAttributeBuilder (
+                                       typeof(ComImportAttribute).GetConstructor (EmptyTypes),
+                                       new object[0] {});
+
+                               typebuilder.SetCustomAttribute (customattr);
+
+                               result = typebuilder.CreateType ();
+
+                               clsid_types.Add(clsid, result);
+
+                               return result;
+                       }
+#else
+                       throw new NotImplementedException ("Unmanaged activation removed");
+#endif
+               }
+
+               protected override TypeCode GetTypeCodeImpl ()
+               {
+                       return GetTypeCodeImplInternal (this);
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern static TypeCode GetTypeCodeImplInternal (Type type);             
+
+               internal static Type GetTypeFromProgIDImpl(String progID, String server, bool throwOnError)
+               {
+                       throw new NotImplementedException ("Unmanaged activation is not supported");
+               }
+
+               public override string ToString()
+               {
+                       return getFullName (false, false);
+               }
+
+               bool IsGenericCOMObjectImpl ()
+               {
+                       return false;
+               }
+
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               static extern object CreateInstanceInternal (Type type);
+
+               public extern override MethodBase DeclaringMethod {
+                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
+                       get;
+               }               
+               
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern string getFullName(bool full_name, bool assembly_qualified);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               public extern override Type [] GetGenericArguments ();
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern GenericParameterAttributes GetGenericParameterAttributes ();
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern Type[] GetGenericParameterConstraints_impl ();
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern int GetGenericParameterPosition ();
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern RuntimeEventInfo[] GetEvents_internal (string name, BindingFlags bindingAttr, Type reflected_type);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern RuntimeFieldInfo[] GetFields_internal (string name, BindingFlags bindingAttr, Type reflected_type);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               public extern override Type[] GetInterfaces();
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern RuntimeType[] GetNestedTypes_internal (string name, BindingFlags bindingAttr);           
+
+               public override string AssemblyQualifiedName {
+                       get {
+                               return getFullName (true, true);
+                       }
+               }
+
+               public extern override Type DeclaringType {
+                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
+                       get;
+               }
+
+               public override string FullName {
+                       get {
+                               throw new NotImplementedException ();
+                       }
+               }
+
+               public extern override string Name {
+                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
+                       get;
+               }
+
+               public extern override string Namespace {
+                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
+                       get;
+               }
+
+               //seclevel { transparent = 0, safe-critical = 1, critical = 2}
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               public extern int get_core_clr_security_level ();
+
+               public override bool IsSecurityTransparent {
+                       get { return get_core_clr_security_level () == 0; }
+               }
+
+               public override bool IsSecurityCritical {
+                       get { return get_core_clr_security_level () > 0; }
+               }
+
+               public override bool IsSecuritySafeCritical {
+                       get { return get_core_clr_security_level () == 1; }
+               }               
+       }
+}
\ No newline at end of file
diff --git a/mcs/class/corlib/ReferenceSources/TypeNameParser.cs b/mcs/class/corlib/ReferenceSources/TypeNameParser.cs
new file mode 100644 (file)
index 0000000..b28a6af
--- /dev/null
@@ -0,0 +1,20 @@
+using System.Reflection;
+using System.Threading;
+
+namespace System
+{
+       internal sealed class TypeNameParser
+       {
+               internal static Type GetType(
+            string typeName,
+            Func<AssemblyName, Assembly> assemblyResolver,
+            Func<Assembly, string, bool, Type> typeResolver,
+            bool throwOnError,
+            bool ignoreCase,
+            ref StackCrawlMark stackMark)
+               {
+                       TypeSpec spec = TypeSpec.Parse (typeName);
+                       return spec.Resolve (assemblyResolver, typeResolver, throwOnError, ignoreCase);
+               }
+       }
+}
\ No newline at end of file
index af03fefbe85183f173f51f63e41cca06b61bf092..b907eaa04a72b2cc67eb4ed9a3bb8bc88af5dba1 100644 (file)
@@ -436,10 +436,9 @@ namespace System.Reflection.Emit
                        return new ByRefType (this);
                }
 
-               [MonoTODO]
-               public override Type MakeGenericType (params Type [] typeArguments)
+               public override Type MakeGenericType (params Type[] typeArguments)
                {
-                       return base.MakeGenericType (typeArguments);
+                       throw new InvalidOperationException (Environment.GetResourceString ("Arg_NotGenericTypeDefinition"));
                }
 
                public override Type MakePointerType ()
index 9a3404a271fae2a65d532a388bb9164e49808a41..edf6d58852807e250a372202a96240db1ef8aa41 100644 (file)
@@ -914,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);
                }
 
@@ -1863,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)
                {
index 6c12b105b33b6845a21979e2e8f7b3498cf0693e..035c08b02aace9c8f2454174f9b73fa81e952754 100644 (file)
@@ -119,6 +119,10 @@ namespace System.Reflection {
                        return MonoCustomAttrs.GetCustomAttributesData (target);
                }
 
+               internal static IList<CustomAttributeData> GetCustomAttributesInternal (RuntimeType target) {
+                       return MonoCustomAttrs.GetCustomAttributesData (target);
+               }
+
                public static IList<CustomAttributeData> GetCustomAttributes (Module target) {
                        return MonoCustomAttrs.GetCustomAttributesData (target);
                }
index 4f354d0a6f7cca75b475c405df3ba0ef370d2abc..1395add035044a7598465401df1ca7f66048394c 100644 (file)
@@ -60,9 +60,18 @@ namespace System.Reflection {
                }
        }
 
+       abstract class RuntimeEventInfo : EventInfo
+       {
+               internal BindingFlags BindingFlags {
+                       get {
+                               return 0;
+                       }
+               }
+       }
+
        [Serializable]
        [StructLayout (LayoutKind.Sequential)]
-       internal sealed class MonoEvent: EventInfo, ISerializable
+       internal sealed class MonoEvent: RuntimeEventInfo, ISerializable
        {
 #pragma warning disable 169
                IntPtr klass;
index 8e170a9b20fb85925c78f638e1f3ffb223235ca0..117eea363fd520e7c1998c4aedd28d2f0f580a37 100644 (file)
@@ -41,7 +41,16 @@ using System.Runtime.Serialization;
 
 namespace System.Reflection {
 
-       abstract class RtFieldInfo : FieldInfo
+       abstract class RuntimeFieldInfo : FieldInfo
+       {
+               internal BindingFlags BindingFlags {
+                       get {
+                               return 0;
+                       }
+               }
+       }
+
+       abstract class RtFieldInfo : RuntimeFieldInfo
        {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                internal extern object UnsafeGetValue (object obj);
index e2848ee80ee433db27fa7dc969a97bf04029a37f..c503c399b37beffd3ba7f7b760b8ee3e01c56074 100644 (file)
@@ -111,6 +111,11 @@ namespace System.Reflection {
        
        abstract class RuntimeMethodInfo : MethodInfo
        {
+               internal BindingFlags BindingFlags {
+                       get {
+                               return 0;
+                       }
+               }
        }
 
        /*
@@ -263,6 +268,9 @@ namespace System.Reflection {
                                var arg = args [i];
                                var pi = pinfo [i];
                                if (arg == Type.Missing) {
+                                       if (pi.DefaultValue == System.DBNull.Value)
+                                               throw new ArgumentException(Environment.GetResourceString("Arg_VarMissNull"),"parameters");
+
                                        args [i] = pi.DefaultValue;
                                        continue;
                                }
@@ -478,6 +486,11 @@ namespace System.Reflection {
 
        abstract class RuntimeConstructorInfo : ConstructorInfo
        {
+               internal BindingFlags BindingFlags {
+                       get {
+                               return 0;
+                       }
+               }
        }
 
        [Serializable()]
index f710da52cdd977cc6333f5947313b187bec60de0..6edaf0de37ca8173818d8258f5c5cd4f6d95792d 100644 (file)
@@ -38,12 +38,17 @@ using System.Runtime.Serialization;
 
 namespace System.Reflection {
 
+       abstract class RuntimeModule : Module
+       {
+               
+       }
+
        [ComVisible (true)]
        [ComDefaultInterfaceAttribute (typeof (_Module))]
        [Serializable]
        [ClassInterface(ClassInterfaceType.None)]
-       class MonoModule : Module {
-
+       class MonoModule : RuntimeModule
+       {
                public
                override
                Assembly Assembly {
@@ -127,6 +132,9 @@ namespace System.Reflection {
                public override
                FieldInfo GetField (string name, BindingFlags bindingAttr) 
                {
+                       if (name == null)
+                               throw new ArgumentNullException("name");
+
                        if (IsResource ())
                                return null;
 
index 162ee87d1e64a86509c869f0f94b207ec17cc6dc..c399b7a55d3b730064473017af48fed95e18d2c5 100644 (file)
@@ -73,9 +73,18 @@ namespace System.Reflection {
        internal delegate object GetterAdapter (object _this);
        internal delegate R Getter<T,R> (T _this);
 
+       abstract class RuntimePropertyInfo : PropertyInfo
+       {
+               internal BindingFlags BindingFlags {
+                       get {
+                               return 0;
+                       }
+               }
+       }
+
        [Serializable]
        [StructLayout (LayoutKind.Sequential)]
-       internal class MonoProperty : PropertyInfo, ISerializable {
+       internal class MonoProperty : RuntimePropertyInfo, ISerializable {
 #pragma warning disable 649
                internal IntPtr klass;
                internal IntPtr prop;
index ab97679e4f0ffbf3f857656ca2161f936b5803c6..d6222065e29dbfb20c052f715de1ebd2db411df6 100644 (file)
@@ -686,8 +686,8 @@ namespace System
 
                        int[] bounds = null;
 
-                       elementType = elementType.UnderlyingSystemType;
-                       if (!elementType.IsSystemType)
+                       elementType = elementType.UnderlyingSystemType as RuntimeType;
+                       if (elementType == null)
                                throw new ArgumentException ("Type must be a type provided by the runtime.", "elementType");
                        if (elementType.Equals (typeof (void)))
                                throw new NotSupportedException ("Array type can not be void");
@@ -710,8 +710,8 @@ namespace System
                        if (lowerBounds == null)
                                throw new ArgumentNullException ("lowerBounds");
 
-                       elementType = elementType.UnderlyingSystemType;
-                       if (!elementType.IsSystemType)
+                       elementType = elementType.UnderlyingSystemType as RuntimeType;
+                       if (elementType == null)
                                throw new ArgumentException ("Type must be a type provided by the runtime.", "elementType");
                        if (elementType.Equals (typeof (void)))
                                throw new NotSupportedException ("Array type can not be void");
index d5d5a8a4b16d17c84af1ed767d372e8aeb26731b..f69fe0c1c28b83f1f488c61e65bcbc38f8f3d9fd 100644 (file)
@@ -34,6 +34,7 @@ using System;
 using System.Reflection;
 using System.Collections;
 using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
 #if !FULL_AOT_RUNTIME
 using System.Reflection.Emit;
 #endif
@@ -79,7 +80,7 @@ namespace System
                        else if (obj is ParameterInfo)
                                pseudoAttrs = ((ParameterInfo)obj).GetPseudoCustomAttributes ();
                        else if (obj is Type)
-                               pseudoAttrs = ((Type)obj).GetPseudoCustomAttributes ();
+                               pseudoAttrs = GetPseudoCustomAttributes (((Type)obj));
 
                        if ((attributeType != null) && (pseudoAttrs != null)) {
                                for (int i = 0; i < pseudoAttrs.Length; ++i)
@@ -94,6 +95,30 @@ namespace System
                        return pseudoAttrs;
                }
 
+               static object[] GetPseudoCustomAttributes (Type type)
+               {
+                       int count = 0;
+                       var Attributes = type.Attributes;
+
+                       /* IsSerializable returns true for delegates/enums as well */
+                       if ((Attributes & TypeAttributes.Serializable) != 0)
+                               count ++;
+                       if ((Attributes & TypeAttributes.Import) != 0)
+                               count ++;
+
+                       if (count == 0)
+                               return null;
+                       object[] attrs = new object [count];
+                       count = 0;
+
+                       if ((Attributes & TypeAttributes.Serializable) != 0)
+                               attrs [count ++] = new SerializableAttribute ();
+                       if ((Attributes & TypeAttributes.Import) != 0)
+                               attrs [count ++] = new ComImportAttribute ();
+
+                       return attrs;
+               }
+
                internal static object[] GetCustomAttributesBase (ICustomAttributeProvider obj, Type attributeType, bool inheritedOnly)
                {
                        object[] attrs;
index 70593e055c06e4f916780b4089a8ba872db9a709..e97a208ef97b2a19bb90c6777171e26d9bf86a2f 100644 (file)
@@ -44,6 +44,7 @@ using System.Threading;
 using System.Diagnostics;
 using System.Security.Permissions;
 using System.Runtime.Remoting.Activation;
+using System.Runtime;
 
 namespace System
 {
@@ -53,899 +54,6 @@ namespace System
                public string full_name;
                public MonoCMethod default_ctor;
        }
-               
-       abstract class RuntimeType : TypeInfo
-       {
-               private static readonly RuntimeType StringType = (RuntimeType)typeof(System.String);
-
-               private static readonly RuntimeType DelegateType = (RuntimeType)typeof(System.Delegate);
-
-               internal RuntimeAssembly GetRuntimeAssembly ()
-               {
-                       return (RuntimeAssembly) Assembly;
-               }
-
-               internal virtual bool IsSzArray {
-                       get {
-                               return IsArrayImpl () && GetArrayRank () == 1;
-                       }
-               }
-
-               bool IsGenericCOMObjectImpl ()
-               {
-                       return false;
-               }
-
-               internal Object CheckValue (Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
-               {
-                       bool failed = false;
-                       var res = TryConvertToType (value, ref failed);
-                       if (!failed)
-                               return res;
-
-                       if ((invokeAttr & BindingFlags.ExactBinding) == BindingFlags.ExactBinding)
-                               throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Arg_ObjObjEx"), value.GetType(), this));
-
-                       if (binder != null && binder != Type.DefaultBinder)
-                               return binder.ChangeType (value, this, culture);
-
-                       throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Arg_ObjObjEx"), value.GetType(), this));
-               }
-
-               object TryConvertToType (object value, ref bool failed)
-               {
-                       if (IsInstanceOfType (value)) {
-                               return value;
-                       }
-
-                       if (IsByRef) {
-                               var elementType = GetElementType ();
-                               if (value == null || elementType.IsInstanceOfType (value)) {
-                                       return value;
-                               }
-                       }
-
-                       if (value == null)
-                               return value;
-
-                       if (IsEnum) {
-                               var type = Enum.GetUnderlyingType (this);
-                               if (type == value.GetType ())
-                                       return value;
-                               var res = IsConvertibleToPrimitiveType (value, this);
-                               if (res != null)
-                                       return res;
-                       } else if (IsPrimitive) {
-                               var res = IsConvertibleToPrimitiveType (value, this);
-                               if (res != null)
-                                       return res;
-                       } else if (IsPointer) {
-                               var vtype = value.GetType ();
-                               if (vtype == typeof (IntPtr) || vtype == typeof (UIntPtr))
-                                       return value;
-                       }
-
-                       failed = true;
-                       return null;
-               }
-
-               // Binder uses some incompatible conversion rules. For example
-               // int value cannot be used with decimal parameter but in other
-               // ways it's more flexible than normal convertor, for example
-               // long value can be used with int based enum
-               static object IsConvertibleToPrimitiveType (object value, Type targetType)
-               {
-                       var type = value.GetType ();
-                       if (type.IsEnum) {
-                               type = Enum.GetUnderlyingType (type);
-                               if (type == targetType)
-                                       return value;
-                       }
-
-                       var from = Type.GetTypeCode (type);
-                       var to = Type.GetTypeCode (targetType);
-
-                       switch (to) {
-                               case TypeCode.Char:
-                                       switch (from) {
-                                               case TypeCode.Byte:
-                                                       return (Char) (Byte) value;
-                                               case TypeCode.UInt16:
-                                                       return value;
-                                       }
-                                       break;
-                               case TypeCode.Int16:
-                                       switch (from) {
-                                               case TypeCode.Byte:
-                                                       return (Int16) (Byte) value;
-                                               case TypeCode.SByte:
-                                                       return (Int16) (SByte) value;
-                                       }
-                                       break;
-                               case TypeCode.UInt16:
-                                       switch (from) {
-                                               case TypeCode.Byte:
-                                                       return (UInt16) (Byte) value;
-                                               case TypeCode.Char:
-                                                       return value;
-                                       }
-                                       break;
-                               case TypeCode.Int32:
-                                       switch (from) {
-                                               case TypeCode.Byte:
-                                                       return (Int32) (Byte) value;
-                                               case TypeCode.SByte:
-                                                       return (Int32) (SByte) value;
-                                               case TypeCode.Char:
-                                                       return (Int32) (Char) value;
-                                               case TypeCode.Int16:
-                                                       return (Int32) (Int16) value;
-                                               case TypeCode.UInt16:
-                                                       return (Int32) (UInt16) value;
-                                       }
-                                       break;
-                               case TypeCode.UInt32:
-                                       switch (from) {
-                                               case TypeCode.Byte:
-                                                       return (UInt32) (Byte) value;
-                                               case TypeCode.Char:
-                                                       return (UInt32) (Char) value;
-                                               case TypeCode.UInt16:
-                                                       return (UInt32) (UInt16) value;
-                                       }
-                                       break;
-                               case TypeCode.Int64:
-                                       switch (from) {
-                                               case TypeCode.Byte:
-                                                       return (Int64) (Byte) value;
-                                               case TypeCode.SByte:
-                                                       return (Int64) (SByte) value;
-                                               case TypeCode.Int16:
-                                                       return (Int64) (Int16) value;
-                                               case TypeCode.Char:
-                                                       return (Int64) (Char) value;
-                                               case TypeCode.UInt16:
-                                                       return (Int64) (UInt16) value;
-                                               case TypeCode.Int32:
-                                                       return (Int64) (Int32) value;
-                                               case TypeCode.UInt32:
-                                                       return (Int64) (UInt32) value;
-                                       }
-                                       break;
-                               case TypeCode.UInt64:
-                                       switch (from) {
-                                               case TypeCode.Byte:
-                                                       return (UInt64) (Byte) value;
-                                               case TypeCode.Char:
-                                                       return (UInt64) (Char) value;
-                                               case TypeCode.UInt16:
-                                                       return (UInt64) (UInt16) value;
-                                               case TypeCode.UInt32:
-                                                       return (UInt64) (UInt32) value;
-                                       }
-                                       break;
-                               case TypeCode.Single:
-                                       switch (from) {
-                                               case TypeCode.Byte:
-                                                       return (Single) (Byte) value;
-                                               case TypeCode.SByte:
-                                                       return (Single) (SByte) value;
-                                               case TypeCode.Int16:
-                                                       return (Single) (Int16) value;
-                                               case TypeCode.Char:
-                                                       return (Single) (Char) value;
-                                               case TypeCode.UInt16:
-                                                       return (Single) (UInt16) value;
-                                               case TypeCode.Int32:
-                                                       return (Single) (Int32) value;
-                                               case TypeCode.UInt32:
-                                                       return (Single) (UInt32) value;
-                                               case TypeCode.Int64:
-                                                       return (Single) (Int64) value;
-                                               case TypeCode.UInt64:
-                                                       return (Single) (UInt64) value;
-                                       }
-                                       break;
-                               case TypeCode.Double:
-                                       switch (from) {
-                                               case TypeCode.Byte:
-                                                       return (Double) (Byte) value;
-                                               case TypeCode.SByte:
-                                                       return (Double) (SByte) value;
-                                               case TypeCode.Char:
-                                                       return (Double) (Char) value;
-                                               case TypeCode.Int16:
-                                                       return (Double) (Int16) value;
-                                               case TypeCode.UInt16:
-                                                       return (Double) (UInt16) value;
-                                               case TypeCode.Int32:
-                                                       return (Double) (Int32) value;
-                                               case TypeCode.UInt32:
-                                                       return (Double) (UInt32) value;
-                                               case TypeCode.Int64:
-                                                       return (Double) (Int64) value;
-                                               case TypeCode.UInt64:
-                                                       return (Double) (UInt64) value;
-                                               case TypeCode.Single:
-                                                       return (Double) (Single) value;
-                                       }
-                                       break;
-                       }
-
-                       // Everything else is rejected
-                       return null;
-               }
-
-        protected ListBuilder<MethodInfo> GetMethodCandidates (MethodInfo[] cache, BindingFlags bindingAttr, CallingConventions callConv, Type[] types)
-        {
-               var candidates = new ListBuilder<MethodInfo> ();
-
-            for (int i = 0; i < cache.Length; i++) {
-                               var methodInfo = cache[i];
-                               if (FilterApplyMethodBase(methodInfo, /*methodInfo.BindingFlags,*/ bindingAttr, callConv, types)) {
-                                       candidates.Add (methodInfo);
-                               }
-                       }
-
-                       return candidates;
-               }
-
-        private static bool FilterApplyConstructorInfo(
-            RuntimeConstructorInfo constructor, BindingFlags bindingFlags, CallingConventions callConv, Type[] argumentTypes)
-        {
-            // Optimization: Pre-Calculate the method binding flags to avoid casting.
-            return FilterApplyMethodBase(constructor, /*constructor.BindingFlags,*/ bindingFlags, callConv, argumentTypes);
-        }
-
-        private static bool FilterApplyMethodBase(
-            MethodBase methodBase, /*BindingFlags methodFlags,*/ BindingFlags bindingFlags, CallingConventions callConv, Type[] argumentTypes)
-        {
-            Contract.Requires(methodBase != null);
-
-            bindingFlags ^= BindingFlags.DeclaredOnly;
-/*
-            #region Apply Base Filter
-            if ((bindingFlags & methodFlags) != methodFlags)
-                return false;
-            #endregion
-*/
-            #region Check CallingConvention
-            if ((callConv & CallingConventions.Any) == 0)
-            {
-                if ((callConv & CallingConventions.VarArgs) != 0 && 
-                    (methodBase.CallingConvention & CallingConventions.VarArgs) == 0)
-                    return false;
-
-                if ((callConv & CallingConventions.Standard) != 0 && 
-                    (methodBase.CallingConvention & CallingConventions.Standard) == 0)
-                    return false;
-            }
-            #endregion
-
-            #region If argumentTypes supplied
-            if (argumentTypes != null)
-            {
-                ParameterInfo[] parameterInfos = methodBase.GetParametersNoCopy();
-
-                if (argumentTypes.Length != parameterInfos.Length)
-                {
-                    #region Invoke Member, Get\Set & Create Instance specific case
-                    // If the number of supplied arguments differs than the number in the signature AND
-                    // we are not filtering for a dynamic call -- InvokeMethod or CreateInstance -- filter out the method.
-                    if ((bindingFlags & 
-                        (BindingFlags.InvokeMethod | BindingFlags.CreateInstance | BindingFlags.GetProperty | BindingFlags.SetProperty)) == 0)
-                        return false;
-                    
-                    bool testForParamArray = false;
-                    bool excessSuppliedArguments = argumentTypes.Length > parameterInfos.Length;
-
-                    if (excessSuppliedArguments) 
-                    { // more supplied arguments than parameters, additional arguments could be vararg
-                        #region Varargs
-                        // If method is not vararg, additional arguments can not be passed as vararg
-                        if ((methodBase.CallingConvention & CallingConventions.VarArgs) == 0)
-                        {
-                            testForParamArray = true;
-                        }
-                        else 
-                        {
-                            // If Binding flags did not include varargs we would have filtered this vararg method.
-                            // This Invariant established during callConv check.
-                            Contract.Assert((callConv & CallingConventions.VarArgs) != 0);
-                        }
-                        #endregion
-                    }
-                    else 
-                    {// fewer supplied arguments than parameters, missing arguments could be optional
-                        #region OptionalParamBinding
-                        if ((bindingFlags & BindingFlags.OptionalParamBinding) == 0)
-                        {
-                            testForParamArray = true;
-                        }
-                        else
-                        {
-                            // From our existing code, our policy here is that if a parameterInfo 
-                            // is optional then all subsequent parameterInfos shall be optional. 
-
-                            // Thus, iff the first parameterInfo is not optional then this MethodInfo is no longer a canidate.
-                            if (!parameterInfos[argumentTypes.Length].IsOptional)
-                                testForParamArray = true;
-                        }
-                        #endregion
-                    }
-
-                    #region ParamArray
-                    if (testForParamArray)
-                    {
-                        if  (parameterInfos.Length == 0)
-                            return false;
-
-                        // The last argument of the signature could be a param array. 
-                        bool shortByMoreThanOneSuppliedArgument = argumentTypes.Length < parameterInfos.Length - 1;
-
-                        if (shortByMoreThanOneSuppliedArgument)
-                            return false;
-
-                        ParameterInfo lastParameter = parameterInfos[parameterInfos.Length - 1];
-
-                        if (!lastParameter.ParameterType.IsArray)
-                            return false;
-
-                        if (!lastParameter.IsDefined(typeof(ParamArrayAttribute), false))
-                            return false;
-                    }
-                    #endregion
-
-                    #endregion
-                }
-                else
-                {
-                    #region Exact Binding
-                    if ((bindingFlags & BindingFlags.ExactBinding) != 0)
-                    {
-                        // Legacy behavior is to ignore ExactBinding when InvokeMember is specified.
-                        // Why filter by InvokeMember? If the answer is we leave this to the binder then why not leave
-                        // all the rest of this  to the binder too? Further, what other semanitc would the binder
-                        // use for BindingFlags.ExactBinding besides this one? Further, why not include CreateInstance 
-                        // in this if statement? That's just InvokeMethod with a constructor, right?
-                        if ((bindingFlags & (BindingFlags.InvokeMethod)) == 0)
-                        {
-                            for(int i = 0; i < parameterInfos.Length; i ++)
-                            {
-                                // a null argument type implies a null arg which is always a perfect match
-                                if ((object)argumentTypes[i] != null && !Object.ReferenceEquals(parameterInfos[i].ParameterType, argumentTypes[i]))
-                                    return false;
-                            }
-                        }
-                    }
-                    #endregion
-                }
-            }
-            #endregion
-        
-            return true;
-        }
-
-        [System.Security.SecurityCritical]  // auto-generated
-        internal Object CreateInstanceImpl(
-            BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, ref StackCrawlMark stackMark)
-        {            
-            CreateInstanceCheckThis();
-            
-            Object server = null;
-
-            try
-            {
-                try
-                {
-                    // Store the activation attributes in thread local storage.
-                    // These attributes are later picked up by specialized 
-                    // activation services like remote activation services to
-                    // influence the activation.
-#if FEATURE_REMOTING
-                    if(null != activationAttributes)
-                    {
-                        ActivationServices.PushActivationAttributes(this, activationAttributes);
-                    }
-#endif                    
-                    
-                    if (args == null)
-                        args = EmptyArray<Object>.Value;
-
-                    int argCnt = args.Length;
-
-                    // Without a binder we need to do use the default binder...
-                    if (binder == null)
-                        binder = DefaultBinder;
-
-                    // deal with the __COMObject case first. It is very special because from a reflection point of view it has no ctors
-                    // so a call to GetMemberCons would fail
-                    if (argCnt == 0 && (bindingAttr & BindingFlags.Public) != 0 && (bindingAttr & BindingFlags.Instance) != 0
-                        && (IsGenericCOMObjectImpl() || IsValueType)) 
-                    {
-                        server = CreateInstanceDefaultCtor((bindingAttr & BindingFlags.NonPublic) == 0 , false, true, ref stackMark);
-                    }
-                    else 
-                    {
-                        ConstructorInfo[] candidates = GetConstructors(bindingAttr);
-                        List<MethodBase> matches = new List<MethodBase>(candidates.Length);
-
-                        // We cannot use Type.GetTypeArray here because some of the args might be null
-                        Type[] argsType = new Type[argCnt];
-                        for (int i = 0; i < argCnt; i++)
-                        {
-                            if (args[i] != null)
-                            {
-                                argsType[i] = args[i].GetType();
-                            }
-                        }
-
-                        for(int i = 0; i < candidates.Length; i ++)
-                        {
-                            if (FilterApplyConstructorInfo((RuntimeConstructorInfo)candidates[i], bindingAttr, CallingConventions.Any, argsType))
-                                matches.Add(candidates[i]);
-                        }
-
-                        MethodBase[] cons = new MethodBase[matches.Count];
-                        matches.CopyTo(cons);
-                        if (cons != null && cons.Length == 0)
-                            cons = null;
-
-                        if (cons == null) 
-                        {
-                            // Null out activation attributes before throwing exception
-#if FEATURE_REMOTING                                            
-                            if(null != activationAttributes)
-                            {
-                                ActivationServices.PopActivationAttributes(this);
-                                activationAttributes = null;
-                            }
-#endif                            
-                            throw new MissingMethodException(Environment.GetResourceString("MissingConstructor_Name", FullName));
-                        }
-
-                        MethodBase invokeMethod;
-                        Object state = null;
-
-                        try
-                        {
-                            invokeMethod = binder.BindToMethod(bindingAttr, cons, ref args, null, culture, null, out state);
-                        }
-                        catch (MissingMethodException) { invokeMethod = null; }
-
-                        if (invokeMethod == null)
-                        {
-#if FEATURE_REMOTING                                            
-                            // Null out activation attributes before throwing exception
-                            if(null != activationAttributes)
-                            {
-                                ActivationServices.PopActivationAttributes(this);
-                                activationAttributes = null;
-                            }                  
-#endif                                
-                            throw new MissingMethodException(Environment.GetResourceString("MissingConstructor_Name", FullName));
-                        }
-
-                        // If we're creating a delegate, we're about to call a
-                        // constructor taking an integer to represent a target
-                        // method. Since this is very difficult (and expensive)
-                        // to verify, we're just going to demand UnmanagedCode
-                        // permission before allowing this. Partially trusted
-                        // clients can instead use Delegate.CreateDelegate,
-                        // which allows specification of the target method via
-                        // name or MethodInfo.
-                        //if (isDelegate)
-                        if (RuntimeType.DelegateType.IsAssignableFrom(invokeMethod.DeclaringType))
-                        {
-#if FEATURE_CORECLR
-                            // In CoreCLR, CAS is not exposed externally. So what we really are looking
-                            // for is to see if the external caller of this API is transparent or not.
-                            // We get that information from the fact that a Demand will succeed only if
-                            // the external caller is not transparent. 
-                            try
-                            {
-#pragma warning disable 618
-                                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
-#pragma warning restore 618
-                            }
-                            catch
-                            {
-                                throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("NotSupported_DelegateCreationFromPT")));
-                            }
-#else // FEATURE_CORECLR
-                            new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
-#endif // FEATURE_CORECLR
-                        }
-
-                        if (invokeMethod.GetParametersNoCopy().Length == 0)
-                        {
-                            if (args.Length != 0)
-                            {
-
-                                Contract.Assert((invokeMethod.CallingConvention & CallingConventions.VarArgs) == 
-                                                 CallingConventions.VarArgs); 
-                                throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, 
-                                    Environment.GetResourceString("NotSupported_CallToVarArg")));
-                            }
-
-                            // fast path??
-                            server = Activator.CreateInstance(this, true);
-                        }
-                        else
-                        {
-                            server = ((ConstructorInfo)invokeMethod).Invoke(bindingAttr, binder, args, culture);
-                            if (state != null)
-                                binder.ReorderArgumentArray(ref args, state);
-                        }
-                    }
-                }                    
-                finally
-                {
-#if FEATURE_REMOTING                
-                    // Reset the TLS to null
-                    if(null != activationAttributes)
-                    {
-                          ActivationServices.PopActivationAttributes(this);
-                          activationAttributes = null;
-                    }
-#endif                    
-                }
-            }
-            catch (Exception)
-            {
-                throw;
-            }
-            
-            //Console.WriteLine(server);
-            return server;                                
-        }
-
-        // Helper to invoke the default (parameterless) ctor.
-        // fillCache is set in the SL2/3 compat mode or when called from Marshal.PtrToStructure.
-        [System.Security.SecuritySafeCritical]  // auto-generated
-        [DebuggerStepThroughAttribute]
-        [Diagnostics.DebuggerHidden]
-        internal Object CreateInstanceDefaultCtor(bool publicOnly, bool skipCheckThis, bool fillCache, ref StackCrawlMark stackMark)
-        {
-            if (GetType() == typeof(ReflectionOnlyType))
-                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAllowedInReflectionOnly"));
-
-/*
-            ActivatorCache activatorCache = s_ActivatorCache;
-            if (activatorCache != null)
-            {
-                ActivatorCacheEntry ace = activatorCache.GetEntry(this);
-                if (ace != null)
-                {
-                    if (publicOnly)
-                    {
-                        if (ace.m_ctor != null && 
-                            (ace.m_ctorAttributes & MethodAttributes.MemberAccessMask) != MethodAttributes.Public)
-                        {
-                            throw new MissingMethodException(Environment.GetResourceString("Arg_NoDefCTor"));
-                        }
-                    }
-                            
-                    // Allocate empty object
-                    Object instance = RuntimeTypeHandle.Allocate(this);
-                    
-                    // if m_ctor is null, this type doesn't have a default ctor
-                    Contract.Assert(ace.m_ctor != null || this.IsValueType);
-
-                    if (ace.m_ctor != null)
-                    {
-                        // Perform security checks if needed
-                        if (ace.m_bNeedSecurityCheck)
-                            RuntimeMethodHandle.PerformSecurityCheck(instance, ace.m_hCtorMethodHandle, this, (uint)INVOCATION_FLAGS.INVOCATION_FLAGS_CONSTRUCTOR_INVOKE);
-
-                        // Call ctor (value types wont have any)
-                        try
-                        {
-                            ace.m_ctor(instance);
-                        }
-                        catch (Exception e)
-                        {
-                            throw new TargetInvocationException(e);
-                        }
-                    }
-                    return instance;
-                }
-            }
-*/
-            return CreateInstanceSlow(publicOnly, skipCheckThis, fillCache, ref stackMark);
-        }
-
-        // the slow path of CreateInstanceDefaultCtor
-        internal Object CreateInstanceSlow(bool publicOnly, bool skipCheckThis, bool fillCache, ref StackCrawlMark stackMark)
-        {
-            bool bNeedSecurityCheck = true;
-            bool bCanBeCached = false;
-            bool bSecurityCheckOff = false;
-
-            if (!skipCheckThis)
-                CreateInstanceCheckThis();
-
-            if (!fillCache)
-                bSecurityCheckOff = true;
-
-            return CreateInstanceMono (!publicOnly);
-        }
-
-        private void CreateInstanceCheckThis()
-        {
-            if (this is ReflectionOnlyType)
-                throw new ArgumentException(Environment.GetResourceString("Arg_ReflectionOnlyInvoke"));
-
-            if (ContainsGenericParameters)
-                throw new ArgumentException(
-                    Environment.GetResourceString("Acc_CreateGenericEx", this));
-            Contract.EndContractBlock();
-
-            Type elementType = this.GetRootElementType();
-
-            if (Object.ReferenceEquals(elementType, typeof(ArgIterator)))
-                throw new NotSupportedException(Environment.GetResourceString("Acc_CreateArgIterator"));
-
-            if (Object.ReferenceEquals(elementType, typeof(void)))
-                throw new NotSupportedException(Environment.GetResourceString("Acc_CreateVoid"));
-        }
-
-               object CreateInstanceMono (bool nonPublic)
-               {
-                       var ctor = GetDefaultConstructor ();
-                       if (!nonPublic && ctor != null && !ctor.IsPublic) {
-                               ctor = null;
-                       }
-
-                       if (ctor == null) {
-                   Type elementType = this.GetRootElementType();
-                   if (ReferenceEquals (elementType, typeof (TypedReference)) || ReferenceEquals (elementType, typeof (RuntimeArgumentHandle)))
-                   throw new NotSupportedException (Environment.GetResourceString ("NotSupported_ContainsStackPtr"));
-
-                               if (IsValueType)
-                                       return CreateInstanceInternal (this);
-
-                               throw new MissingMethodException (Locale.GetText ("Default constructor not found for type " + FullName));
-                       }
-
-                       // TODO: .net does more checks in unmanaged land in RuntimeTypeHandle::CreateInstance
-                       if (IsAbstract) {
-                               throw new MissingMethodException (Locale.GetText ("Cannot create an abstract class '{0}'.", FullName));
-                       }
-
-                       return ctor.InternalInvoke (null, null);
-               }
-
-        #region Enums
-        public override string[] GetEnumNames()
-        {
-            if (!IsEnum)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
-            Contract.EndContractBlock();
-
-            String[] ret = Enum.InternalGetNames(this);
-
-            // Make a copy since we can't hand out the same array since users can modify them
-            String[] retVal = new String[ret.Length];
-
-            Array.Copy(ret, retVal, ret.Length);
-
-            return retVal;
-        }
-
-        [SecuritySafeCritical]
-        public override Array GetEnumValues()
-        {
-            if (!IsEnum)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
-            Contract.EndContractBlock();
-
-            // Get all of the values
-            ulong[] values = Enum.InternalGetValues(this);
-
-            // Create a generic Array
-            Array ret = Array.UnsafeCreateInstance(this, values.Length);
-
-            for (int i = 0; i < values.Length; i++)
-            {
-                Object val = Enum.ToObject(this, values[i]);
-                ret.SetValue(val, i);
-            }
-
-            return ret;
-        }
-
-        public override Type GetEnumUnderlyingType()
-        {
-            if (!IsEnum)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
-            Contract.EndContractBlock();
-
-            return Enum.InternalGetUnderlyingType(this);
-        }
-
-        public override bool IsEnumDefined(object value)
-        {
-            if (value == null)
-                throw new ArgumentNullException("value");
-            Contract.EndContractBlock();
-
-            // Check if both of them are of the same type
-            RuntimeType valueType = (RuntimeType)value.GetType();
-
-            // If the value is an Enum then we need to extract the underlying value from it
-            if (valueType.IsEnum)
-            {
-                if (!valueType.IsEquivalentTo(this))
-                    throw new ArgumentException(Environment.GetResourceString("Arg_EnumAndObjectMustBeSameType", valueType.ToString(), this.ToString()));
-
-                valueType = (RuntimeType)valueType.GetEnumUnderlyingType();
-            }
-
-            // If a string is passed in
-            if (valueType == RuntimeType.StringType)
-            {
-                // Get all of the Fields, calling GetHashEntry directly to avoid copying
-                string[] names = Enum.InternalGetNames(this);
-                if (Array.IndexOf(names, value) >= 0)
-                    return true;
-                else
-                    return false;
-            }
-
-            // If an enum or integer value is passed in
-            if (Type.IsIntegerType(valueType))
-            {
-                RuntimeType underlyingType = Enum.InternalGetUnderlyingType(this);
-                if (underlyingType != valueType)
-                    throw new ArgumentException(Environment.GetResourceString("Arg_EnumUnderlyingTypeAndObjectMustBeSameType", valueType.ToString(), underlyingType.ToString()));
-
-                ulong[] ulValues = Enum.InternalGetValues(this);
-                ulong ulValue = Enum.ToUInt64(value);
-
-                return (Array.BinarySearch(ulValues, ulValue) >= 0);
-            }
-            else if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
-            {
-                // if at this point the value type is not an integer type, then its type doesn't match the enum type
-                // NetCF used to throw an argument exception in this case
-                throw new ArgumentException(Environment.GetResourceString("Arg_EnumUnderlyingTypeAndObjectMustBeSameType", valueType.ToString(), GetEnumUnderlyingType()));
-            }
-            else
-            {
-                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_UnknownEnumType"));
-            }
-        }
-
-        public override string GetEnumName(object value)
-        {
-            if (value == null)
-                throw new ArgumentNullException("value");
-            Contract.EndContractBlock();
-
-            Type valueType = value.GetType();
-
-            if (!(valueType.IsEnum || IsIntegerType(valueType)))
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), "value");
-
-            ulong[] ulValues = Enum.InternalGetValues(this);
-            ulong ulValue = Enum.ToUInt64(value);
-            int index = Array.BinarySearch(ulValues, ulValue);
-
-            if (index >= 0)
-            {
-                string[] names = Enum.InternalGetNames(this);
-                return names[index];
-            }
-
-            return null;
-        }
-        #endregion     
-
-               internal abstract MonoCMethod GetDefaultConstructor ();
-
-        // Helper to build lists of MemberInfos. Special cased to avoid allocations for lists of one element.
-        protected struct ListBuilder<T> where T : class
-        {
-            T[] _items;
-            T _item;
-            int _count;
-            int _capacity;
-
-            public ListBuilder(int capacity)
-            {
-                _items = null;
-                _item = null;
-                _count = 0;
-                _capacity = capacity;
-            }
-
-            public T this[int index]
-            {
-                get
-                {
-                    Contract.Requires(index < Count);
-                    return (_items != null) ? _items[index] : _item;
-                }
-#if FEATURE_LEGACYNETCF
-                // added for Dev11 466969 quirk
-                set
-                {
-                    Contract.Requires(index < Count);
-                    if (_items != null)
-                        _items[index] = value;
-                    else
-                        _item = value;
-                }
-#endif
-            }
-
-            public T[] ToArray()
-            {
-                if (_count == 0)
-                    return EmptyArray<T>.Value;
-                if (_count == 1)
-                    return new T[1] { _item };
-
-                Array.Resize(ref _items, _count);
-                _capacity = _count;
-                return _items;
-            }
-
-            public void CopyTo(Object[] array, int index)
-            {
-                if (_count == 0)
-                    return;
-
-                if (_count == 1)
-                {
-                    array[index] = _item;
-                    return;
-                }
-
-                Array.Copy(_items, 0, array, index, _count);
-            }
-
-            public int Count
-            {
-                get
-                {
-                    return _count;
-                }
-            }
-
-            public void Add(T item)
-            {
-                if (_count == 0)
-                {
-                    _item = item;
-                }
-                else                
-                {
-                    if (_count == 1)
-                    {
-                        if (_capacity < 2)
-                            _capacity = 4;
-                        _items = new T[_capacity];
-                        _items[0] = _item;
-                    }
-                    else
-                    if (_capacity == _count)
-                    {
-                        int newCapacity = 2 * _capacity;
-                        Array.Resize(ref _items, newCapacity);
-                        _capacity = newCapacity;
-                    }
-
-                    _items[_count] = item;
-                }
-                _count++;
-            }
-        }
-
-               [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               static extern object CreateInstanceInternal (Type type);
-       }
 
        [Serializable]
        [StructLayout (LayoutKind.Sequential)]
@@ -965,9 +73,6 @@ namespace System
                        throw new NotImplementedException ();
                }
 
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private static extern TypeAttributes get_attributes (Type type);
-
                internal override MonoCMethod GetDefaultConstructor ()
                {
                        MonoCMethod ctor = null;
@@ -991,168 +96,6 @@ namespace System
                        return ctor;
                }
 
-               protected override TypeAttributes GetAttributeFlagsImpl ()
-               {
-                       return get_attributes (this);
-               }
-
-               protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
-                                                                      Binder binder,
-                                                                      CallingConventions callConvention,
-                                                                      Type[] types,
-                                                                      ParameterModifier[] modifiers)
-               {
-                       ConstructorInfo[] candidates = GetConstructors (bindingAttr);
-
-                       if (candidates.Length == 0)
-                               return null;
-
-                       if (types.Length == 0 && candidates.Length == 1) {
-                               ConstructorInfo firstCandidate = candidates [0];
-                               var parameters = firstCandidate.GetParametersNoCopy ();
-                               if (parameters == null || parameters.Length == 0)
-                                       return firstCandidate;
-                       }
-
-                       if ((bindingAttr & BindingFlags.ExactBinding) != 0)
-                               return (ConstructorInfo) System.DefaultBinder.ExactBinding (candidates, types, modifiers);
-
-                       if (binder == null)
-                               binder = DefaultBinder;
-
-                       return (ConstructorInfo) CheckMethodSecurity (binder.SelectMethod (bindingAttr, candidates, types, modifiers));
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal extern ConstructorInfo[] GetConstructors_internal (BindingFlags bindingAttr, Type reflected_type);
-
-               public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
-               {
-                       return GetConstructors_internal (bindingAttr, this);
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern EventInfo InternalGetEvent (string name, BindingFlags bindingAttr);
-
-               public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-
-                       return InternalGetEvent (name, bindingAttr);
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal extern EventInfo[] GetEvents_internal (BindingFlags bindingAttr, Type reflected_type);
-
-               public override EventInfo[] GetEvents (BindingFlags bindingAttr)
-               {
-                       return GetEvents_internal (bindingAttr, this);
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               public extern override FieldInfo GetField (string name, BindingFlags bindingAttr);
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal extern FieldInfo[] GetFields_internal (BindingFlags bindingAttr, Type reflected_type);
-
-               public override FieldInfo[] GetFields (BindingFlags bindingAttr)
-               {
-                       return GetFields_internal (bindingAttr, this);
-               }
-               
-               public override Type GetInterface (string name, bool ignoreCase)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException ();
-
-                       Type[] interfaces = GetInterfaces();
-
-                       foreach (Type type in interfaces) {
-                               /*We must compare against the generic type definition*/
-                               Type t = type.IsGenericType ? type.GetGenericTypeDefinition () : type;
-
-                               if (String.Compare (t.Name, name, ignoreCase, CultureInfo.InvariantCulture) == 0)
-                                       return type;
-                               if (String.Compare (t.FullName, name, ignoreCase, CultureInfo.InvariantCulture) == 0)
-                                       return type;
-                       }
-
-                       return null;
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               public extern override Type[] GetInterfaces();
-
-               public override InterfaceMapping GetInterfaceMap (Type interfaceType)
-               {
-                       if (!IsSystemType)
-                               throw new NotSupportedException ("Derived classes must provide an implementation.");
-                       if (interfaceType == null)
-                               throw new ArgumentNullException ("interfaceType");
-                       if (!interfaceType.IsSystemType)
-                               throw new ArgumentException ("interfaceType", "Type is an user type");
-                       InterfaceMapping res;
-                       if (!interfaceType.IsInterface)
-                               throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "interfaceType");
-                       if (IsInterface)
-                               throw new ArgumentException ("'this' type cannot be an interface itself");
-                       res.TargetType = this;
-                       res.InterfaceType = interfaceType;
-                       GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
-                       if (res.TargetMethods == null)
-                               throw new ArgumentException (Locale.GetText ("Interface not found"), "interfaceType");
-
-                       return res;
-               }
-               
-               public override MemberInfo[] GetMembers( BindingFlags bindingAttr)
-               {
-                       return FindMembers (MemberTypes.All, bindingAttr, null, null);
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal extern MethodInfo [] GetMethodsByName (string name, BindingFlags bindingAttr, bool ignoreCase, Type reflected_type);
-
-               public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
-               {
-                       return GetMethodsByName (null, bindingAttr, false, this);
-               }
-
-               protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
-                                                            Binder binder,
-                                                            CallingConventions callConvention,
-                                                            Type[] types, ParameterModifier[] modifiers)
-               {
-                       bool ignoreCase = ((bindingAttr & BindingFlags.IgnoreCase) != 0);
-                       var candidates = GetMethodCandidates (GetMethodsByName (name, bindingAttr, ignoreCase, this), bindingAttr, callConvention, types);
-
-                       if (candidates.Count == 0)
-                               return null;
-                       
-                       if (types == null || types.Length == 0) {
-                               var firstCandidate = candidates [0];
-                               if (candidates.Count == 1)
-                                       return firstCandidate;
-
-                               if (types == null) {
-                                       for (int j = 1; j < candidates.Count; j++) {
-                                               MethodInfo methodInfo = candidates [j];
-                                               if (!System.DefaultBinder.CompareMethodSigAndName (methodInfo, firstCandidate))
-                                                       throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
-                                       }
-
-                                       // All the methods have the exact same name and sig so return the most derived one.
-                                       return (MethodInfo) System.DefaultBinder.FindMostDerivedNewSlotMeth (candidates.ToArray (), candidates.Count);
-                               }
-                       }
-
-                       if (binder == null)
-                               binder = DefaultBinder;
-                       
-                       return (MethodInfo) CheckMethodSecurity (binder.SelectMethod (bindingAttr, candidates.ToArray (), types, modifiers));
-               }
-
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                extern MethodInfo GetCorrespondingInflatedMethod (MethodInfo generic);
 
@@ -1181,264 +124,12 @@ namespace System
                        return GetField (fromNoninstanciated.Name, flags);
                }
 
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               public extern override Type GetNestedType (string name, BindingFlags bindingAttr);
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               public extern override Type[] GetNestedTypes (BindingFlags bindingAttr);
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal extern PropertyInfo[] GetPropertiesByName (string name, BindingFlags bindingAttr, bool icase, Type reflected_type);
-
-               public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
-               {
-                       return GetPropertiesByName (null, bindingAttr, false, this);
-               }
-
-               protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
-                                                                Binder binder, Type returnType,
-                                                                Type[] types,
-                                                                ParameterModifier[] modifiers)
+               public override int GetHashCode()
                {
-                       bool ignoreCase = ((bindingAttr & BindingFlags.IgnoreCase) != 0);
-                       PropertyInfo [] props = GetPropertiesByName (name, bindingAttr, ignoreCase, this);
-                       int count = props.Length;
-                       if (count == 0)
-                               return null;
-                       
-                       if (types == null || types.Length == 0) {
-                               if (count == 1) {
-                                       var firstCandidate = props [0];
-
-                                       if ((object)returnType != null && !returnType.IsEquivalentTo (firstCandidate.PropertyType))
-                                               return null;
-
-                                       return firstCandidate;
-                               }
-
-                               throw new AmbiguousMatchException (Environment.GetResourceString("Arg_AmbiguousMatchException"));
-                       }
-
-                       if ((bindingAttr & BindingFlags.ExactBinding) != 0)
-                               return System.DefaultBinder.ExactPropertyBinding (props, returnType, types, modifiers);
-
-                       if (binder == null)
-                               binder = DefaultBinder;
-
-                       return binder.SelectProperty (bindingAttr, props, returnType, types, modifiers);
-               }
-
-               protected override bool HasElementTypeImpl ()
-               {
-                       return IsArrayImpl() || IsByRefImpl() || IsPointerImpl ();
-               }
-
-               protected override bool IsArrayImpl ()
-               {
-                       return Type.IsArrayImpl (this);
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               protected extern override bool IsByRefImpl ();
-
-               [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               protected extern override bool IsCOMObjectImpl ();
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               protected extern override bool IsPointerImpl ();
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               protected extern override bool IsPrimitiveImpl ();
-
-               public override bool IsSubclassOf (Type type)
-               {
-                       if (type == null)
-                               throw new ArgumentNullException ("type");
-
-                       return base.IsSubclassOf (type);
-               }
-
-               public override object InvokeMember (string name, BindingFlags invokeAttr,
-                                                    Binder binder, object target, object[] args,
-                                                    ParameterModifier[] modifiers,
-                                                    CultureInfo culture, string[] namedParameters)
-               {
-                       const string bindingflags_arg = "bindingFlags";
-
-
-                       if ((invokeAttr & BindingFlags.CreateInstance) != 0) {
-                               if ((invokeAttr & (BindingFlags.GetField |
-                                               BindingFlags.GetField | BindingFlags.GetProperty |
-                                               BindingFlags.SetProperty)) != 0)
-                                       throw new ArgumentException (bindingflags_arg);
-                       } else if (name == null)
-                               throw new ArgumentNullException ("name");
-                       if ((invokeAttr & BindingFlags.GetField) != 0 && (invokeAttr & BindingFlags.SetField) != 0)
-                               throw new ArgumentException ("Cannot specify both Get and Set on a field.", bindingflags_arg);
-                       if ((invokeAttr & BindingFlags.GetProperty) != 0 && (invokeAttr & BindingFlags.SetProperty) != 0)
-                               throw new ArgumentException ("Cannot specify both Get and Set on a property.", bindingflags_arg);
-                       if ((invokeAttr & BindingFlags.InvokeMethod) != 0) {
-                               if ((invokeAttr & BindingFlags.SetField) != 0)
-                                       throw new ArgumentException ("Cannot specify Set on a field and Invoke on a method.", bindingflags_arg);
-                               if ((invokeAttr & BindingFlags.SetProperty) != 0)
-                                       throw new ArgumentException ("Cannot specify Set on a property and Invoke on a method.", bindingflags_arg);
-                       }
-                       if ((namedParameters != null) && ((args == null) || args.Length < namedParameters.Length))
-                               throw new ArgumentException ("namedParameters cannot be more than named arguments in number");
-                       if ((invokeAttr & (BindingFlags.InvokeMethod|BindingFlags.CreateInstance|BindingFlags.GetField|BindingFlags.SetField|BindingFlags.GetProperty|BindingFlags.SetProperty)) == 0)
-                               throw new ArgumentException ("Must specify binding flags describing the invoke operation required.", bindingflags_arg);
-
-                       /* set some defaults if none are provided :-( */
-                       if ((invokeAttr & (BindingFlags.Public|BindingFlags.NonPublic)) == 0)
-                               invokeAttr |= BindingFlags.Public;
-                       if ((invokeAttr & (BindingFlags.Static|BindingFlags.Instance)) == 0)
-                               invokeAttr |= BindingFlags.Static|BindingFlags.Instance;
-
-                       if (binder == null)
-                               binder = DefaultBinder;
-
-                       if ((invokeAttr & BindingFlags.CreateInstance) != 0) {
-                               return Activator.CreateInstance (this, invokeAttr, binder, args, culture);
-                       }
-                       if (name == String.Empty && Attribute.IsDefined (this, typeof (DefaultMemberAttribute))) {
-                               DefaultMemberAttribute attr = (DefaultMemberAttribute) Attribute.GetCustomAttribute (this, typeof (DefaultMemberAttribute));
-                               name = attr.MemberName;
-                       }
-                       bool ignoreCase = (invokeAttr & BindingFlags.IgnoreCase) != 0;
-                       string throwMissingMethodDescription = null;
-                       bool throwMissingFieldException = false;
-                       
-                       if ((invokeAttr & BindingFlags.InvokeMethod) != 0) {
-                               MethodInfo[] methods = GetMethodsByName (name, invokeAttr, ignoreCase, this);
-                               object state = null;
-                               if (args == null)
-                                       args = EmptyArray<object>.Value;
-                               MethodBase m = binder.BindToMethod (invokeAttr, methods, ref args, modifiers, culture, namedParameters, out state);
-                               if (m == null) {
-                                       if (methods.Length > 0)
-                                               throwMissingMethodDescription = "The best match for method " + name + " has some invalid parameter.";
-                                       else
-                                               throwMissingMethodDescription = "Cannot find method " + name + ".";
-                               } else {
-                                       ParameterInfo[] parameters = m.GetParametersInternal();
-                                       for (int i = 0; i < parameters.Length; ++i) {
-                                               if (System.Reflection.Missing.Value == args [i] && (parameters [i].Attributes & ParameterAttributes.HasDefault) != ParameterAttributes.HasDefault)
-                                                       throw new ArgumentException ("Used Missing.Value for argument without default value", "parameters");
-                                       }
-                                       object result = m.Invoke (target, invokeAttr, binder, args, culture);
-                                       if (state != null)
-                                               binder.ReorderArgumentArray (ref args, state);
-                                       return result;
-                               }
-                       }
-                       if ((invokeAttr & BindingFlags.GetField) != 0) {
-                               FieldInfo f = GetField (name, invokeAttr);
-                               if (f != null) {
-                                       return f.GetValue (target);
-                               } else if ((invokeAttr & BindingFlags.GetProperty) == 0) {
-                                       throwMissingFieldException = true;
-                               }
-                               /* try GetProperty */
-                       } else if ((invokeAttr & BindingFlags.SetField) != 0) {
-                               FieldInfo f = GetField (name, invokeAttr);
-                               if (f != null) {
-                                       if (args == null)
-                                               throw new ArgumentNullException ("providedArgs");
-                                       if ((args == null) || args.Length != 1)
-                                               throw new ArgumentException ("Only the field value can be specified to set a field value.", bindingflags_arg);
-                                       f.SetValue (target, args [0]);
-                                       return null;
-                               } else if ((invokeAttr & BindingFlags.SetProperty) == 0) {
-                                       throwMissingFieldException = true;
-                               }
-                               /* try SetProperty */
-                       }
-                       if ((invokeAttr & BindingFlags.GetProperty) != 0) {
-                               PropertyInfo[] properties = GetPropertiesByName (name, invokeAttr, ignoreCase, this);
-                               object state = null;
-                               if (args == null)
-                                       args = EmptyArray<object>.Value;
-                               int i, count = 0;
-                               for (i = 0; i < properties.Length; ++i) {
-                                       if ((properties [i].GetGetMethod (true) != null))
-                                               count++;
-                               }
-                               MethodBase[] smethods = new MethodBase [count];
-                               count = 0;
-                               for (i = 0; i < properties.Length; ++i) {
-                                       MethodBase mb = properties [i].GetGetMethod (true);
-                                       if (mb != null)
-                                               smethods [count++] = mb;
-                               }
-                               MethodBase m = count > 0 ? binder.BindToMethod (invokeAttr, smethods, ref args, modifiers, culture, namedParameters, out state) : null;
-                               if (m == null) {
-                                       throwMissingMethodDescription = "Cannot find method `" + name + "'.";
-                               } else {
-                                       object result = m.Invoke (target, invokeAttr, binder, args, culture);
-                                       if (state != null)
-                                               binder.ReorderArgumentArray (ref args, state);
-                                       return result;
-                               }
-                       } else if ((invokeAttr & BindingFlags.SetProperty) != 0) {
-                               PropertyInfo[] properties = GetPropertiesByName (name, invokeAttr, ignoreCase, this);
-                               object state = null;
-                               int i, count = 0;
-                               for (i = 0; i < properties.Length; ++i) {
-                                       if (properties [i].GetSetMethod (true) != null)
-                                               count++;
-                               }
-                               MethodBase[] smethods = new MethodBase [count];
-                               count = 0;
-                               for (i = 0; i < properties.Length; ++i) {
-                                       MethodBase mb = properties [i].GetSetMethod (true);
-                                       if (mb != null)
-                                               smethods [count++] = mb;
-                               }
-                               MethodBase m = count > 0 ? binder.BindToMethod (invokeAttr, smethods, ref args, modifiers, culture, namedParameters, out state) : null;
-                               if (m == null) {
-                                       throwMissingMethodDescription = "Cannot find method `" + name + "'.";
-                               } else {
-                                       object result = m.Invoke (target, invokeAttr, binder, args, culture);
-                                       if (state != null)
-                                               binder.ReorderArgumentArray (ref args, state);
-                                       return result;
-                               }
-                       }
-                       if (throwMissingMethodDescription != null)
-                               throw new MissingMethodException(throwMissingMethodDescription);
-                       if (throwMissingFieldException)
-                               throw new MissingFieldException("Cannot find variable " + name + ".");
-
-                       return null;
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               public extern override Type GetElementType ();
-
-               public override Type UnderlyingSystemType {
-                       get {
-                               // This has _nothing_ to do with getting the base type of an enum etc.
-                               return this;
-                       }
-               }
-
-               public extern override Assembly Assembly {
-                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
-                       get;
-               }
-
-               public override string AssemblyQualifiedName {
-                       get {
-                               return getFullName (true, true);
-                       }
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private extern string getFullName(bool full_name, bool assembly_qualified);
-
-               public extern override Type BaseType {
-                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
-                       get;
+                       Type t = UnderlyingSystemType;
+                       if (t != null && t != this)
+                               return t.GetHashCode ();
+                       return (int)_impl.Value;
                }
 
                public override string FullName {
@@ -1454,207 +145,10 @@ namespace System
                        }
                }
 
-               public override Guid GUID {
-                       get {
-                               object[] att = GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), true);
-                               if (att.Length == 0)
-                                       return Guid.Empty;
-                               return new Guid(((System.Runtime.InteropServices.GuidAttribute)att[0]).Value);
-                       }
-               }
-
-               public override bool IsDefined (Type attributeType, bool inherit)
-               {
-                       return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
-               }
-
-               public override object[] GetCustomAttributes (bool inherit)
-               {
-                       return MonoCustomAttrs.GetCustomAttributes (this, inherit);
-               }
-
-               public override object[] GetCustomAttributes (Type attributeType, bool inherit)
-               {
-                       if (attributeType == null)
-                       {
-                               throw new ArgumentNullException("attributeType");
-                       }
-                       
-                       return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
-               }
-
-               public override MemberTypes MemberType {
-                       get {
-                               if (DeclaringType != null && !IsGenericParameter)
-                                       return MemberTypes.NestedType;
-                               else
-                                       return MemberTypes.TypeInfo;
-                       }
-               }
-
-               public extern override string Name {
-                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
-                       get;
-               }
-
-               public extern override string Namespace {
-                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
-                       get;
-               }
-
-               public extern override Module Module {
-                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
-                       get;
-               }
-
-               public extern override Type DeclaringType {
-                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
-                       get;
-               }
-
-               public override Type ReflectedType {
-                       get {
-                               return DeclaringType;
-                       }
-               }
-
-               public override RuntimeTypeHandle TypeHandle {
-                       get {
-                               return _impl;
-                       }
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               public extern override int GetArrayRank ();
-
-               public void GetObjectData(SerializationInfo info, StreamingContext context)
-               {
-                       UnitySerializationHolder.GetUnitySerializationInfo(info, this);
-               }
-
-               public override string ToString()
-               {
-                       return getFullName (false, false);
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               public extern override Type [] GetGenericArguments ();
-
-               public override bool ContainsGenericParameters {
-                       get {
-                               if (IsGenericParameter)
-                                       return true;
-
-                               if (IsGenericType) {
-                                       foreach (Type arg in GetGenericArguments ())
-                                               if (arg.ContainsGenericParameters)
-                                                       return true;
-                               }
-
-                               if (HasElementType)
-                                       return GetElementType ().ContainsGenericParameters;
-
-                               return false;
-                       }
-               }
-
-               public extern override bool IsGenericParameter {
-                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
-                       get;
-               }
-
-               public extern override MethodBase DeclaringMethod {
-                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
-                       get;
-               }
-
-               public override Type GetGenericTypeDefinition () {
-                       Type res = GetGenericTypeDefinition_impl ();
-                       if (res == null)
-                               throw new InvalidOperationException ();
-
-                       return res;
-               }
-
-               public override IList<CustomAttributeData> GetCustomAttributesData () {
-                       return CustomAttributeData.GetCustomAttributes (this);
-               }
-
-
-               public override Array GetEnumValues ()
-               {
-            if (!IsEnum)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
-            Contract.EndContractBlock();
-
-            // Get all of the values
-            ulong[] values = Enum.InternalGetValues(this);
-
-            // Create a generic Array
-            Array ret = Array.UnsafeCreateInstance(this, values.Length);
-
-            for (int i = 0; i < values.Length; i++)
-            {
-                Object val = Enum.ToObject(this, values[i]);
-                ret.SetValue(val, i);
-            }
-
-            return ret;
-               }
-
-               static MethodBase CheckMethodSecurity (MethodBase mb)
-               {
-#if NET_2_1
-                       return mb;
-#else
-                       if (!SecurityManager.SecurityEnabled || (mb == null))
-                               return mb;
-
-                       // Sadly we have no way to know which kind of security action this is
-                       // so we must do it the hard way. Actually this isn't so bad 
-                       // because we can skip the (mb.Attributes & MethodAttributes.HasSecurity)
-                       // icall required (and do it ourselves)
-
-                       // this (unlike the Invoke step) is _and stays_ a LinkDemand (caller)
-                       return SecurityManager.ReflectedLinkDemandQuery (mb) ? mb : null;
-#endif
-               }
-
-               //seclevel { transparent = 0, safe-critical = 1, critical = 2}
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               public extern int get_core_clr_security_level ();
-
-               public override bool IsSecurityTransparent
-               {
-                       get { return get_core_clr_security_level () == 0; }
-               }
-
-               public override bool IsSecurityCritical
-               {
-                       get { return get_core_clr_security_level () > 0; }
-               }
-
-               public override bool IsSecuritySafeCritical
-               {
-                       get { return get_core_clr_security_level () == 1; }
-               }
-
-               public override StructLayoutAttribute StructLayoutAttribute {
-                       get {
-                               return GetStructLayoutAttribute ();
-                       }
-               }
-
                internal override bool IsUserType {
                        get {
                                return false;
                        }
                }
-
-               public override bool IsConstructedGenericType {
-                       get {
-                               return IsGenericType && !ContainsGenericParameters;
-                       }
-               }
        }
 }
index 45fc6edaff2e43719ff92349156f9bc5230ae9ed..64c1cb7083ef4647cc737c65a9a15a58b7167e81 100644 (file)
 using System.Runtime.Serialization;
 using System.Runtime.InteropServices;
 using System.Runtime.ConstrainedExecution;
+using System.Threading;
+using System.Runtime.CompilerServices;
+using System.Reflection;
+using System.Diagnostics.Contracts;
 
 namespace System
 {
@@ -48,6 +52,11 @@ namespace System
                        value = val;
                }
 
+               internal RuntimeTypeHandle (RuntimeType type)
+                       : this (type._impl.value)
+               {
+               }
+
                RuntimeTypeHandle (SerializationInfo info, StreamingContext context)
                {
                        if (info == null)
@@ -116,6 +125,9 @@ namespace System
                        return (left == null) || !(left is RuntimeTypeHandle) || !((RuntimeTypeHandle)left).Equals (right);
                }
 
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal static extern TypeAttributes GetAttributes (RuntimeType type);
+
                [CLSCompliant (false)]
                [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
                public ModuleHandle GetModuleHandle ()
@@ -128,5 +140,113 @@ namespace System
 
                        return Type.GetTypeFromHandle (this).Module.ModuleHandle;
                }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               static extern int GetMetadataToken (RuntimeType type);
+
+               internal static int GetToken (RuntimeType type)
+               {
+                       return GetMetadataToken (type);
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern static Type GetGenericTypeDefinition_impl (RuntimeType type);
+
+               internal static Type GetGenericTypeDefinition (RuntimeType type)
+               {
+                       return GetGenericTypeDefinition_impl (type);
+               }
+
+               internal static bool HasElementType (RuntimeType type)
+               {
+                       return IsArray (type) || IsByRef (type) || IsPointer (type);
+               }
+
+               internal static bool HasProxyAttribute (RuntimeType type)
+               {
+                       throw new NotImplementedException ("HasProxyAttribute");
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static bool HasInstantiation (RuntimeType type);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static bool IsArray(RuntimeType type);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static bool IsByRef (RuntimeType type);
+
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               internal extern static bool IsComObject (RuntimeType type);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static bool IsInstanceOfType (RuntimeType type, Object o);              
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static bool IsPointer (RuntimeType type);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static bool IsPrimitive (RuntimeType type);
+
+               internal static bool IsComObject (RuntimeType type, bool isGenericCOM)
+               {
+                       return isGenericCOM ? false : IsComObject (type);
+               }
+
+               internal static bool IsContextful (RuntimeType type)
+               {
+                       return typeof (ContextBoundObject).IsAssignableFrom (type);
+               }
+
+               internal static bool IsEquivalentTo (RuntimeType rtType1, RuntimeType rtType2)
+               {
+                       // refence check is done earlier and we don't recognize anything else
+                       return false;
+               }               
+
+               internal static bool IsSzArray(RuntimeType type)
+               {
+                       // TODO: Better check
+                       return IsArray (type) && type.GetArrayRank () == 1;
+               }
+
+               internal static bool IsVisible (RuntimeType type)
+               {
+                       return type.IsPublic;
+               }
+
+               internal static bool IsInterface (RuntimeType type)
+               {
+                       return (type.Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static int GetArrayRank(RuntimeType type);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static RuntimeAssembly GetAssembly (RuntimeType type);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static RuntimeType GetElementType (RuntimeType type);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static RuntimeModule GetModule (RuntimeType type);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static bool IsGenericVariable (RuntimeType type);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static RuntimeType GetBaseType (RuntimeType type);
+
+               internal static bool CanCastTo (RuntimeType type, RuntimeType target)
+               {
+                       return type_is_assignable_from (target, type);
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               static extern bool type_is_assignable_from (Type a, Type b);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern static bool IsGenericTypeDefinition (RuntimeType type);
        }
 }
diff --git a/mcs/class/corlib/System/Type.cs b/mcs/class/corlib/System/Type.cs
deleted file mode 100644 (file)
index 9237fde..0000000
+++ /dev/null
@@ -1,1825 +0,0 @@
-//
-// System.Type.cs
-//
-// Authors:
-//   Miguel de Icaza (miguel@ximian.com)
-//   Marek Safar (marek.safar@gmail.com)
-//
-// (C) Ximian, Inc.  http://www.ximian.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System.Diagnostics;
-using System.Reflection;
-#if !FULL_AOT_RUNTIME
-using System.Reflection.Emit;
-#endif
-using System.Collections;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-using System.Threading;
-using System.Globalization;
-using System.Diagnostics.Contracts;
-
-namespace System {
-
-       [Serializable]
-       [ClassInterface (ClassInterfaceType.None)]
-       [ComVisible (true)]
-       [ComDefaultInterface (typeof (_Type))]
-       [StructLayout (LayoutKind.Sequential)]
-#if MOBILE
-       public abstract class Type : MemberInfo, IReflect {
-#else
-       public abstract class Type : MemberInfo, IReflect, _Type {
-#endif
-
-               internal RuntimeTypeHandle _impl;
-
-               public static readonly char Delimiter = '.';
-               public static readonly Type[] EmptyTypes = {};
-               public static readonly MemberFilter FilterAttribute = new MemberFilter (FilterAttribute_impl);
-               public static readonly MemberFilter FilterName = new MemberFilter (FilterName_impl);
-               public static readonly MemberFilter FilterNameIgnoreCase = new MemberFilter (FilterNameIgnoreCase_impl);
-               public static readonly object Missing = System.Reflection.Missing.Value;
-
-               internal const BindingFlags DefaultBindingFlags =
-               BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
-
-               /* implementation of the delegates for MemberFilter */
-               static bool FilterName_impl (MemberInfo m, object filterCriteria)
-               {
-                       string name = (string) filterCriteria;
-                       if (name == null || name.Length == 0 )
-                               return false; // because m.Name cannot be null or empty
-                       
-                       if (name [name.Length - 1] == '*')
-                               return m.Name.StartsWithOrdinalUnchecked (name.Substring (0, name.Length - 1));
-                       
-                       return m.Name == name;
-               }
-
-               static bool FilterNameIgnoreCase_impl (MemberInfo m, object filterCriteria)
-               {
-                       string name = (string) filterCriteria;
-                       if (name == null || name.Length == 0 )
-                               return false; // because m.Name cannot be null or empty
-                               
-                       if (name [name.Length - 1] == '*')
-                               return m.Name.StartsWithOrdinalCaseInsensitiveUnchecked (name.Substring (0, name.Length - 1));
-                       
-                       return string.CompareOrdinalCaseInsensitiveUnchecked (m.Name, name) == 0;
-               }
-
-               static bool FilterAttribute_impl (MemberInfo m, object filterCriteria)
-               {
-                       if (!(filterCriteria is int))
-                               throw new InvalidFilterCriteriaException ("Int32 value is expected for filter criteria");
-
-                       int flags = (int) filterCriteria;
-                       if (m is MethodInfo)
-                               return ((int)((MethodInfo)m).Attributes & flags) != 0;
-                       if (m is FieldInfo)
-                               return ((int)((FieldInfo)m).Attributes & flags) != 0;
-                       if (m is PropertyInfo)
-                               return ((int)((PropertyInfo)m).Attributes & flags) != 0;
-                       if (m is EventInfo)
-                               return ((int)((EventInfo)m).Attributes & flags) != 0;
-                       return false;
-               }
-
-               protected Type ()
-               {
-               }
-
-               /// <summary>
-               ///   The assembly where the type is defined.
-               /// </summary>
-               public abstract Assembly Assembly {
-                       get;
-               }
-
-               /// <summary>
-               ///   Gets the fully qualified name for the type including the
-               ///   assembly name where the type is defined.
-               /// </summary>
-               public abstract string AssemblyQualifiedName {
-                       get;
-               }
-
-               /// <summary>
-               ///   Returns the Attributes associated with the type.
-               /// </summary>
-               public TypeAttributes Attributes {
-                       get {
-                               return GetAttributeFlagsImpl ();
-                       }
-               }
-
-               /// <summary>
-               ///   Returns the basetype for this type
-               /// </summary>
-               public abstract Type BaseType {
-                       get;
-               }
-
-               /// <summary>
-               ///   Returns the class that declares the member.
-               /// </summary>
-               public override Type DeclaringType {
-                       get {
-                               return null;
-                       }
-               }
-
-               /// <summary>
-               ///
-               /// </summary>
-               public static Binder DefaultBinder {
-                       get {
-                               if (defaultBinder == null)
-                                       Interlocked.CompareExchange<Binder> (ref defaultBinder, new DefaultBinder (), null);
-
-                               return defaultBinder;
-                       }
-               }
-
-               static Binder defaultBinder;
-
-               /// <summary>
-               ///    The full name of the type including its namespace
-               /// </summary>
-               public abstract string FullName {
-                       get;
-               }
-
-               public abstract Guid GUID {
-                       get;
-               }
-
-               public bool HasElementType {
-                       get {
-                               return HasElementTypeImpl ();
-                       }
-               }
-
-               public bool IsAbstract {
-                       get {
-                               return (Attributes & TypeAttributes.Abstract) != 0;
-                       }
-               }
-
-               public bool IsAnsiClass {
-                       get {
-                               return (Attributes & TypeAttributes.StringFormatMask)
-                               == TypeAttributes.AnsiClass;
-                       }
-               }
-
-               public bool IsArray {
-                       get {
-                               return IsArrayImpl ();
-                       }
-               }
-
-               public bool IsAutoClass {
-                       get {
-                               return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass;
-                       }
-               }
-
-               public bool IsAutoLayout {
-                       get {
-                               return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout;
-                       }
-               }
-
-               public bool IsByRef {
-                       get {
-                               return IsByRefImpl ();
-                       }
-               }
-
-               public bool IsClass {
-                       get {
-                               if (IsInterface)
-                                       return false;
-
-                               return !IsValueType;
-                       }
-               }
-
-               public bool IsCOMObject {
-                       get {
-                               return IsCOMObjectImpl ();
-                       }
-               }
-               
-               public virtual bool IsConstructedGenericType {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-               }
-
-               public bool IsContextful {
-                       get {
-                               return IsContextfulImpl ();
-                       }
-               }
-
-               public
-               virtual
-               bool IsEnum {
-                       get {
-                               return IsSubclassOf (typeof (Enum));
-                       }
-               }
-
-               public bool IsExplicitLayout {
-                       get {
-                               return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout;
-                       }
-               }
-
-               public bool IsImport {
-                       get {
-                               return (Attributes & TypeAttributes.Import) != 0;
-                       }
-               }
-
-               public bool IsInterface {
-                       get {
-                               return (Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
-                       }
-               }
-
-               public bool IsLayoutSequential {
-                       get {
-                               return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout;
-                       }
-               }
-
-               public bool IsMarshalByRef {
-                       get {
-                               return IsMarshalByRefImpl ();
-                       }
-               }
-
-               public bool IsNestedAssembly {
-                       get {
-                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly;
-                       }
-               }
-
-               public bool IsNestedFamANDAssem {
-                       get {
-                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem;
-                       }
-               }
-
-               public bool IsNestedFamily {
-                       get {
-                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily;
-                       }
-               }
-
-               public bool IsNestedFamORAssem {
-                       get {
-                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem;
-                       }
-               }
-
-               public bool IsNestedPrivate {
-                       get {
-                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate;
-                       }
-               }
-
-               public bool IsNestedPublic {
-                       get {
-                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic;
-                       }
-               }
-
-               public bool IsNotPublic {
-                       get {
-                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic;
-                       }
-               }
-
-               public bool IsPointer {
-                       get {
-                               return IsPointerImpl ();
-                       }
-               }
-
-               public bool IsPrimitive {
-                       get {
-                               return IsPrimitiveImpl ();
-                       }
-               }
-
-               public bool IsPublic {
-                       get {
-                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public;
-                       }
-               }
-
-               public bool IsSealed {
-                       get {
-                               return (Attributes & TypeAttributes.Sealed) != 0;
-                       }
-               }
-
-               public
-               virtual
-               bool IsSerializable {
-                       get {
-                               if ((Attributes & TypeAttributes.Serializable) != 0)
-                                       return true;
-
-                               // Enums and delegates are always serializable
-
-                               Type type = UnderlyingSystemType;
-                               if (type == null)
-                                       return false;
-
-                               // Fast check for system types
-                               if (type.IsSystemType)
-                                       return type_is_subtype_of (type, typeof (Enum), false) || type_is_subtype_of (type, typeof (Delegate), false);
-
-                               // User defined types depend on this behavior
-                               do {
-                                       if ((type == typeof (Enum)) || (type == typeof (Delegate)))
-                                               return true;
-
-                                       type = type.BaseType;
-                               } while (type != null);
-
-                               return false;
-                       }
-               }
-
-               public bool IsSpecialName {
-                       get {
-                               return (Attributes & TypeAttributes.SpecialName) != 0;
-                       }
-               }
-
-               public bool IsUnicodeClass {
-                       get {
-                               return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass;
-                       }
-               }
-
-               public bool IsValueType {
-                       get {
-                               return IsValueTypeImpl ();
-                       }
-               }
-
-               public override MemberTypes MemberType {
-                       get {
-                               return MemberTypes.TypeInfo;
-                       }
-               }
-
-               public abstract override Module Module {
-                       get;
-               }
-       
-               public abstract string Namespace {get;}
-
-               public override Type ReflectedType {
-                       get {
-                               return null;
-                       }
-               }
-
-               public virtual RuntimeTypeHandle TypeHandle {
-                       get { throw new ArgumentException ("Derived class must provide implementation."); }
-               }
-
-               [ComVisible (true)]
-               public ConstructorInfo TypeInitializer {
-                       get {
-                               return GetConstructorImpl (
-                                       BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
-                                       null,
-                                       CallingConventions.Any,
-                                       EmptyTypes,
-                                       null);
-                       }
-               }
-
-               /*
-                * This has NOTHING to do with getting the base type of an enum. Use
-                * Enum.GetUnderlyingType () for that.
-                */
-               public abstract Type UnderlyingSystemType {get;}
-
-               public override bool Equals (object o)
-               {
-                       return Equals (o as Type);
-               }
-
-               public virtual bool Equals (Type o)
-               {
-                       if ((object)o == (object)this)
-                               return true;
-                       if ((object)o == null)
-                               return false;
-                       Type me = UnderlyingSystemType;
-                       if ((object)me == null)
-                               return false;
-
-                       o = o.UnderlyingSystemType;
-                       if ((object)o == null)
-                               return false;
-                       if ((object)o == (object)this)
-                               return true;
-                       return me.EqualsInternal (o);
-               }               
-               [MonoTODO ("Implement it properly once 4.0 impl details are known.")]
-               public static bool operator == (Type left, Type right)
-               {
-                       return Object.ReferenceEquals (left, right);
-               }
-
-               [MonoTODO ("Implement it properly once 4.0 impl details are known.")]
-               public static bool operator != (Type left, Type right)
-               {
-                       return !Object.ReferenceEquals (left, right);
-               }
-
-               static NotImplementedException CreateNIE () {
-                       return new NotImplementedException ();
-               }
-
-               public static Type GetType (string typeName, Func<AssemblyName,Assembly> assemblyResolver, Func<Assembly,string,bool,Type> typeResolver)
-               {
-                       return GetType (typeName, assemblyResolver, typeResolver, false, false);
-               }
-       
-               public static Type GetType (string typeName, Func<AssemblyName,Assembly> assemblyResolver, Func<Assembly,string,bool,Type> typeResolver, bool throwOnError)
-               {
-                       return GetType (typeName, assemblyResolver, typeResolver, throwOnError, false);
-               }
-       
-               public static Type GetType (string typeName, Func<AssemblyName,Assembly> assemblyResolver, Func<Assembly,string,bool,Type> typeResolver, bool throwOnError, bool ignoreCase)
-               {
-                       TypeSpec spec = TypeSpec.Parse (typeName);
-                       return spec.Resolve (assemblyResolver, typeResolver, throwOnError, ignoreCase);
-               }
-
-               public virtual bool IsSecurityTransparent
-               {
-                       get { throw CreateNIE (); }
-               }
-
-               public virtual bool IsSecurityCritical
-               {
-                       get { throw CreateNIE (); }
-               }
-
-               public virtual bool IsSecuritySafeCritical
-               {
-                       get { throw CreateNIE (); }
-               }
-               
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal extern bool EqualsInternal (Type type);
-               
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private static extern Type internal_from_handle (IntPtr handle);
-               
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private static extern Type internal_from_name (string name, bool throwOnError, bool ignoreCase);
-
-               public static Type GetType(string typeName)
-               {
-                       if (typeName == null)
-                               throw new ArgumentNullException ("TypeName");
-
-                       return internal_from_name (typeName, false, false);
-               }
-
-               public static Type GetType(string typeName, bool throwOnError)
-               {
-                       if (typeName == null)
-                               throw new ArgumentNullException ("TypeName");
-
-                       Type type = internal_from_name (typeName, throwOnError, false);
-                       if (throwOnError && type == null)
-                               throw new TypeLoadException ("Error loading '" + typeName + "'");
-
-                       return type;
-               }
-
-               public static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
-               {
-                       if (typeName == null)
-                               throw new ArgumentNullException ("TypeName");
-
-                       Type t = internal_from_name (typeName, throwOnError, ignoreCase);
-                       if (throwOnError && t == null)
-                               throw new TypeLoadException ("Error loading '" + typeName + "'");
-
-                       return t;
-               }
-
-               public static Type[] GetTypeArray (object[] args) {
-                       if (args == null)
-                               throw new ArgumentNullException ("args");
-
-                       Type[] ret;
-                       ret = new Type [args.Length];
-                       for (int i = 0; i < args.Length; ++i)
-                               ret [i] = args[i].GetType ();
-                       return ret;
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal extern static TypeCode GetTypeCodeInternal (Type type);
-
-               protected virtual
-               TypeCode GetTypeCodeImpl () {
-                       Type type = this;
-                       if (type is MonoType)
-                               return GetTypeCodeInternal (type);
-#if !FULL_AOT_RUNTIME
-                       if (type is TypeBuilder)
-                               return ((TypeBuilder)type).GetTypeCodeInternal ();
-#endif
-
-                       type = type.UnderlyingSystemType;
-
-                       if (!type.IsSystemType)
-                               return TypeCode.Object;
-                       else
-                               return GetTypeCodeInternal (type);
-               }
-
-               public static TypeCode GetTypeCode (Type type) {
-                       if (type == null)
-                               /* MS.NET returns this */
-                               return TypeCode.Empty;
-                       return type.GetTypeCodeImpl ();
-               }
-
-#if !FULL_AOT_RUNTIME
-               private static Dictionary<Guid, Type> clsid_types;
-               private static AssemblyBuilder clsid_assemblybuilder;
-#endif
-
-               [MonoTODO("COM servers only work on Windows")]
-               public static Type GetTypeFromCLSID (Guid clsid)
-               {
-                       return GetTypeFromCLSID (clsid, null, true);
-               }
-
-               [MonoTODO("COM servers only work on Windows")]
-               public static Type GetTypeFromCLSID (Guid clsid, bool throwOnError)
-               {
-                       return GetTypeFromCLSID (clsid, null, throwOnError);
-               }
-
-               [MonoTODO("COM servers only work on Windows")]
-               public static Type GetTypeFromCLSID (Guid clsid, string server)
-               {
-                       return GetTypeFromCLSID (clsid, server, true);
-               }
-
-               [MonoTODO("COM servers only work on Windows")]
-               public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError)
-               {
-#if !FULL_AOT_RUNTIME
-                       Type result;
-
-                       if (clsid_types == null)
-                       {
-                               Dictionary<Guid, Type> new_clsid_types = new Dictionary<Guid, Type> ();
-                               Interlocked.CompareExchange<Dictionary<Guid, Type>>(
-                                       ref clsid_types, new_clsid_types, null);
-                       }
-
-                       lock (clsid_types) {
-                               if (clsid_types.TryGetValue(clsid, out result))
-                                       return result;
-
-                               if (clsid_assemblybuilder == null)
-                               {
-                                       AssemblyName assemblyname = new AssemblyName ();
-                                       assemblyname.Name = "GetTypeFromCLSIDDummyAssembly";
-                                       clsid_assemblybuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (
-                                               assemblyname, AssemblyBuilderAccess.Run);
-                               }
-                               ModuleBuilder modulebuilder = clsid_assemblybuilder.DefineDynamicModule (
-                                       clsid.ToString ());
-
-                               TypeBuilder typebuilder = modulebuilder.DefineType ("System.__ComObject",
-                                       TypeAttributes.Public | TypeAttributes.Class, typeof(System.__ComObject));
-
-                               Type[] guidattrtypes = new Type[] { typeof(string) };
-
-                               CustomAttributeBuilder customattr = new CustomAttributeBuilder (
-                                       typeof(GuidAttribute).GetConstructor (guidattrtypes),
-                                       new object[] { clsid.ToString () });
-
-                               typebuilder.SetCustomAttribute (customattr);
-
-                               customattr = new CustomAttributeBuilder (
-                                       typeof(ComImportAttribute).GetConstructor (EmptyTypes),
-                                       new object[0] {});
-
-                               typebuilder.SetCustomAttribute (customattr);
-
-                               result = typebuilder.CreateType ();
-
-                               clsid_types.Add(clsid, result);
-
-                               return result;
-                       }
-#else
-                       throw new NotImplementedException ();
-#endif
-               }
-
-               public static Type GetTypeFromHandle (RuntimeTypeHandle handle)
-               {
-                       if (handle.Value == IntPtr.Zero)
-                               // This is not consistent with the other GetXXXFromHandle methods, but
-                               // MS.NET seems to do this
-                               return null;
-
-                       return internal_from_handle (handle.Value);
-               }
-
-               [MonoTODO("Mono does not support COM")]
-               public static Type GetTypeFromProgID (string progID)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               [MonoTODO("Mono does not support COM")]
-               public static Type GetTypeFromProgID (string progID, bool throwOnError)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               [MonoTODO("Mono does not support COM")]
-               public static Type GetTypeFromProgID (string progID, string server)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               [MonoTODO("Mono does not support COM")]
-               public static Type GetTypeFromProgID (string progID, string server, bool throwOnError)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public static RuntimeTypeHandle GetTypeHandle (object o)
-               {
-                       if (o == null)
-                               throw new ArgumentNullException ();
-
-                       return o.GetType().TypeHandle;
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal static extern bool type_is_subtype_of (Type a, Type b, bool check_interfaces);
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal static extern bool type_is_assignable_from (Type a, Type b);
-
-               public new Type GetType ()
-               {
-                       return base.GetType ();
-               }
-
-               [ComVisible (true)]
-               public virtual bool IsSubclassOf (Type c)
-               {
-                       if (c == null || c == this)
-                               return false;
-
-                       // Fast check for system types
-                       if (IsSystemType)
-                               return c.IsSystemType && type_is_subtype_of (this, c, false);
-
-                       // User defined types depend on this behavior
-                       for (Type type = BaseType; type != null; type = type.BaseType)
-                               if (type == c)
-                                       return true;
-
-                       return false;
-               }
-
-               public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
-               {
-                       if (filter == null)
-                               throw new ArgumentNullException ("filter");
-
-                       var ifaces = new List<Type> ();
-                       foreach (Type iface in GetInterfaces ()) {
-                               if (filter (iface, filterCriteria))
-                                       ifaces.Add (iface);
-                       }
-
-                       return ifaces.ToArray ();
-               }
-               
-               public Type GetInterface (string name) {
-                       return GetInterface (name, false);
-               }
-
-               public abstract Type GetInterface (string name, bool ignoreCase);
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
-
-               [ComVisible (true)]
-               public virtual InterfaceMapping GetInterfaceMap (Type interfaceType)
-               {
-                       throw new NotSupportedException ();
-               }
-
-               public abstract Type[] GetInterfaces ();
-
-               public virtual bool IsAssignableFrom (Type c)
-               {
-                       if (c == null)
-                               return false;
-
-                       if (Equals (c))
-                               return true;
-
-#if !FULL_AOT_RUNTIME
-                       if (c is TypeBuilder)
-                               return ((TypeBuilder)c).IsAssignableTo (this);
-#endif
-
-                       /* Handle user defined type classes */
-                       if (!IsSystemType) {
-                               Type systemType = UnderlyingSystemType;
-                               if (!systemType.IsSystemType)
-                                       return false;
-
-                               Type other = c.UnderlyingSystemType;
-                               if (!other.IsSystemType)
-                                       return false;
-
-                               return systemType.IsAssignableFrom (other);
-                       }
-
-                       if (!c.IsSystemType) {
-                               Type underlyingType = c.UnderlyingSystemType;
-                               if (!underlyingType.IsSystemType)
-                                       return false;
-                               return IsAssignableFrom (underlyingType);
-                       }
-
-                       return type_is_assignable_from (this, c);
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern static bool IsInstanceOfType (Type type, object o);
-
-               public virtual bool IsInstanceOfType (object o)
-               {
-                       Type type = UnderlyingSystemType;
-                       if (!type.IsSystemType)
-                               return false;
-                       return IsInstanceOfType (type, o);
-               }
-
-               public virtual int GetArrayRank ()
-               {
-                       throw new NotSupportedException ();     // according to MSDN
-               }
-
-               public abstract Type GetElementType ();
-
-               public EventInfo GetEvent (string name)
-               {
-                       return GetEvent (name, DefaultBindingFlags);
-               }
-
-               public abstract EventInfo GetEvent (string name, BindingFlags bindingAttr);
-
-               public virtual EventInfo[] GetEvents ()
-               {
-                       return GetEvents (DefaultBindingFlags);
-               }
-
-               public abstract EventInfo[] GetEvents (BindingFlags bindingAttr);
-
-               public FieldInfo GetField( string name)
-               {
-                       return GetField (name, DefaultBindingFlags);
-               }
-
-               public abstract FieldInfo GetField( string name, BindingFlags bindingAttr);
-
-               public FieldInfo[] GetFields ()
-               {
-                       return GetFields (DefaultBindingFlags);
-               }
-
-               public abstract FieldInfo[] GetFields (BindingFlags bindingAttr);
-               
-               public override int GetHashCode()
-               {
-                       Type t = UnderlyingSystemType;
-                       if (t != null && t != this)
-                               return t.GetHashCode ();
-                       return (int)_impl.Value;
-               }
-
-               public MemberInfo[] GetMember (string name)
-               {
-                       return GetMember (name, MemberTypes.All, DefaultBindingFlags);
-               }
-               
-               public virtual MemberInfo[] GetMember (string name, BindingFlags bindingAttr)
-               {
-                       return GetMember (name, MemberTypes.All, bindingAttr);
-               }
-
-               public virtual MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-                       if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
-                               return FindMembers (type, bindingAttr, FilterNameIgnoreCase, name);
-                       else
-                               return FindMembers (type, bindingAttr, FilterName, name);
-               }
-
-               public MemberInfo[] GetMembers ()
-               {
-                       return GetMembers (DefaultBindingFlags);
-               }
-
-               public abstract MemberInfo[] GetMembers (BindingFlags bindingAttr);
-
-               public MethodInfo GetMethod (string name)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-                       return GetMethodImpl (name, DefaultBindingFlags, null, CallingConventions.Any, null, null);
-               }
-
-               public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-                       
-                       return GetMethodImpl (name, bindingAttr, null, CallingConventions.Any, null, null);
-               }
-               
-               public MethodInfo GetMethod (string name, Type[] types)
-               {
-                       return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, null);
-               }
-
-               public MethodInfo GetMethod (string name, Type[] types, ParameterModifier[] modifiers)
-               {
-                       return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, modifiers);
-               }
-
-               public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
-                                            Type[] types, ParameterModifier[] modifiers)
-               {
-                       return GetMethod (name, bindingAttr, binder, CallingConventions.Any, types, modifiers);
-               }
-
-               public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
-                                            CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-                       if (types == null)
-                               throw new ArgumentNullException ("types");
-
-                       for (int i = 0; i < types.Length; i++) 
-                               if (types[i] == null)
-                                       throw new ArgumentNullException ("types");
-
-                       return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
-               }
-
-               protected abstract MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
-                                                            CallingConventions callConvention, Type[] types,
-                                                            ParameterModifier[] modifiers);
-
-               internal MethodInfo GetMethodImplInternal (string name, BindingFlags bindingAttr, Binder binder,
-                                                                                                                       CallingConventions callConvention, Type[] types,
-                                                                                                                       ParameterModifier[] modifiers)
-               {
-                       return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
-               }
-
-               internal virtual MethodInfo GetMethod (MethodInfo fromNoninstanciated)
-                {
-                       throw new System.InvalidOperationException ("can only be called in generic type");
-                }
-
-               internal virtual ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
-                {
-                       throw new System.InvalidOperationException ("can only be called in generic type");
-                }
-
-               internal virtual FieldInfo GetField (FieldInfo fromNoninstanciated)
-                {
-                       throw new System.InvalidOperationException ("can only be called in generic type");
-                }
-
-               
-               public MethodInfo[] GetMethods ()
-               {
-                       return GetMethods (DefaultBindingFlags);
-               }
-
-               public abstract MethodInfo[] GetMethods (BindingFlags bindingAttr);
-
-               public Type GetNestedType (string name)
-               {
-                       return GetNestedType (name, DefaultBindingFlags);
-               }
-
-               public abstract Type GetNestedType (string name, BindingFlags bindingAttr);
-
-               public Type[] GetNestedTypes ()
-               {
-                       return GetNestedTypes (DefaultBindingFlags);
-               }
-
-               public abstract Type[] GetNestedTypes (BindingFlags bindingAttr);
-
-
-               public PropertyInfo[] GetProperties ()
-               {
-                       return GetProperties (DefaultBindingFlags);
-               }
-
-               public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
-
-
-               public PropertyInfo GetProperty (string name)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-
-                       return GetPropertyImpl (name, DefaultBindingFlags, null, null, null, null);
-               }
-
-               public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-                       return GetPropertyImpl (name, bindingAttr, null, null, null, null);
-               }
-
-               public PropertyInfo GetProperty (string name, Type returnType)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-                       return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, null, null);
-               }
-
-               public PropertyInfo GetProperty (string name, Type[] types)
-               {
-                       return GetProperty (name, DefaultBindingFlags, null, null, types, null);
-               }
-
-               public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
-               {
-                       return GetProperty (name, DefaultBindingFlags, null, returnType, types, null);
-               }
-
-               public PropertyInfo GetProperty( string name, Type returnType, Type[] types, ParameterModifier[] modifiers)
-               {
-                       return GetProperty (name, DefaultBindingFlags, null, returnType, types, modifiers);
-               }
-
-               public PropertyInfo GetProperty (string name, BindingFlags bindingAttr, Binder binder, Type returnType,
-                                                Type[] types, ParameterModifier[] modifiers)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-                       if (types == null)
-                               throw new ArgumentNullException ("types");
-
-                       foreach (Type t in types) {
-                               if (t == null)
-                                       throw new ArgumentNullException ("types");
-                       }
-
-                       return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
-               }
-
-               internal PropertyInfo GetProperty(String name, BindingFlags bindingAttr, Type returnType)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException("name");
-                       if (returnType == null)
-                               throw new ArgumentNullException("returnType");
-                       Contract.EndContractBlock();
-                       return GetPropertyImpl(name, bindingAttr, null, returnType, null, null);
-               }
-
-               protected abstract PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
-                                                                Type returnType, Type[] types, ParameterModifier[] modifiers);
-
-               internal PropertyInfo GetPropertyImplInternal (string name, BindingFlags bindingAttr, Binder binder,
-                                                                                                          Type returnType, Type[] types, ParameterModifier[] modifiers)
-               {
-                       return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
-               }
-
-               protected abstract ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
-                                                                      Binder binder,
-                                                                      CallingConventions callConvention,
-                                                                      Type[] types,
-                                                                      ParameterModifier[] modifiers);
-
-               protected abstract TypeAttributes GetAttributeFlagsImpl ();
-               protected abstract bool HasElementTypeImpl ();
-               protected abstract bool IsArrayImpl ();
-               protected abstract bool IsByRefImpl ();
-               protected abstract bool IsCOMObjectImpl ();
-               protected abstract bool IsPointerImpl ();
-               protected abstract bool IsPrimitiveImpl ();
-               
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal static extern bool IsArrayImpl (Type type);
-
-               protected virtual bool IsValueTypeImpl ()
-               {
-                       if (this == typeof (ValueType) || this == typeof (Enum))
-                               return false;
-
-                       return IsSubclassOf (typeof (ValueType));
-               }
-               
-               protected virtual bool IsContextfulImpl ()
-               {
-                       return typeof (ContextBoundObject).IsAssignableFrom (this);
-               }
-
-               protected virtual bool IsMarshalByRefImpl ()
-               {
-                       return typeof (MarshalByRefObject).IsAssignableFrom (this);
-               }
-
-               [ComVisible (true)]
-               public ConstructorInfo GetConstructor (Type[] types)
-               {
-                       return GetConstructor (BindingFlags.Public|BindingFlags.Instance, null, CallingConventions.Any, types, null);
-               }
-
-               [ComVisible (true)]
-               public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
-                                                      Type[] types, ParameterModifier[] modifiers)
-               {
-                       return GetConstructor (bindingAttr, binder, CallingConventions.Any, types, modifiers);
-               }
-
-               [ComVisible (true)]
-               public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
-                                                      CallingConventions callConvention,
-                                                      Type[] types, ParameterModifier[] modifiers)
-               {
-                       if (types == null)
-                               throw new ArgumentNullException ("types");
-
-                       foreach (Type t in types) {
-                               if (t == null)
-                                       throw new ArgumentNullException ("types");
-                       }
-
-                       return GetConstructorImpl (bindingAttr, binder, callConvention, types, modifiers);
-               }
-
-               [ComVisible (true)]
-               public ConstructorInfo[] GetConstructors ()
-               {
-                       return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
-               }
-
-               [ComVisible (true)]
-               public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
-
-               public virtual MemberInfo[] GetDefaultMembers ()
-               {
-                       object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
-                       if (att.Length == 0)
-                               return EmptyArray<MemberInfo>.Value;
-
-                       MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
-                       return (member != null) ? member : EmptyArray<MemberInfo>.Value;
-               }
-
-               public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,
-                                                        MemberFilter filter, object filterCriteria)
-               {
-                       MemberInfo[] result;
-                       ArrayList l = new ArrayList ();
-
-                       if ((memberType & MemberTypes.Method) != 0) {
-                               MethodInfo[] c = GetMethods (bindingAttr);
-                               if (filter != null) {
-                                       foreach (MemberInfo m in c) {
-                                               if (filter (m, filterCriteria))
-                                                       l.Add (m);
-                                       }
-                               } else {
-                                       l.AddRange (c);
-                               }
-                       }
-                       if ((memberType & MemberTypes.Constructor) != 0) {
-                               ConstructorInfo[] c = GetConstructors (bindingAttr);
-                               if (filter != null) {
-                                       foreach (MemberInfo m in c) {
-                                               if (filter (m, filterCriteria))
-                                                       l.Add (m);
-                                       }
-                               } else {
-                                       l.AddRange (c);
-                               }
-                       }
-                       if ((memberType & MemberTypes.Property) != 0) {
-                               PropertyInfo[] c = GetProperties (bindingAttr);
-
-
-                               if (filter != null) {
-                                       foreach (MemberInfo m in c) {
-                                               if (filter (m, filterCriteria))
-                                                       l.Add (m);
-                                       }
-                               } else {
-                                       l.AddRange (c);
-                               }
-
-                       }
-                       if ((memberType & MemberTypes.Event) != 0) {
-                               EventInfo[] c = GetEvents (bindingAttr);
-                               if (filter != null) {
-                                       foreach (MemberInfo m in c) {
-                                               if (filter (m, filterCriteria))
-                                                       l.Add (m);
-                                       }
-                               } else {
-                                       l.AddRange (c);
-                               }
-                       }
-                       if ((memberType & MemberTypes.Field) != 0) {
-                               FieldInfo[] c = GetFields (bindingAttr);
-                               if (filter != null) {
-                                       foreach (MemberInfo m in c) {
-                                               if (filter (m, filterCriteria))
-                                                       l.Add (m);
-                                       }
-                               } else {
-                                       l.AddRange (c);
-                               }
-                       }
-                       if ((memberType & MemberTypes.NestedType) != 0) {
-                               Type[] c = GetNestedTypes (bindingAttr);
-                               if (filter != null) {
-                                       foreach (MemberInfo m in c) {
-                                               if (filter (m, filterCriteria)) {
-                                                       l.Add (m);
-                                               }
-                                       }
-                               } else {
-                                       l.AddRange (c);
-                               }
-                       }
-
-                       switch (memberType) {
-                       case MemberTypes.Constructor :
-                               result = new ConstructorInfo [l.Count];
-                               break;
-                       case MemberTypes.Event :
-                               result = new EventInfo [l.Count];
-                               break;
-                       case MemberTypes.Field :
-                               result = new FieldInfo [l.Count];
-                               break;
-                       case MemberTypes.Method :
-                               result = new MethodInfo [l.Count];
-                               break;
-                       case MemberTypes.NestedType :
-                       case MemberTypes.TypeInfo :
-                               result = new Type [l.Count];
-                               break;
-                       case MemberTypes.Property :
-                               result = new PropertyInfo [l.Count];
-                               break;
-                       default :
-                               result = new MemberInfo [l.Count];
-                               break;
-                       }
-                       l.CopyTo (result);
-                       return result;
-               }
-
-               [DebuggerHidden]
-               [DebuggerStepThrough] 
-               public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args)
-               {
-                       return InvokeMember (name, invokeAttr, binder, target, args, null, null, null);
-               }
-
-               [DebuggerHidden]
-               [DebuggerStepThrough] 
-               public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
-                                           object target, object[] args, CultureInfo culture)
-               {
-                       return InvokeMember (name, invokeAttr, binder, target, args, null, culture, null);
-               }
-
-               public abstract object InvokeMember (string name, BindingFlags invokeAttr,
-                                                    Binder binder, object target, object[] args,
-                                                    ParameterModifier[] modifiers,
-                                                    CultureInfo culture, string[] namedParameters);
-
-               public override string ToString()
-               {
-                       return FullName;
-               }
-
-               internal static bool ShouldPrintFullName (Type type)
-               {
-                       while (type.HasElementType)
-                               type = type.GetElementType ();
-
-                       if (type == typeof (void) || type.IsNested)
-                               return false;
-
-                       return !type.IsPrimitive;
-               }
-
-               internal virtual Type InternalResolve ()
-               {
-                       return UnderlyingSystemType;
-               }
-
-               internal bool IsSystemType {
-                       get {
-                               return _impl.Value != IntPtr.Zero;
-                       }
-               }
-               
-               public virtual Type[] GenericTypeArguments {
-                       get {
-                               return IsGenericType ? GetGenericArguments () : EmptyTypes;
-                       }
-               }
-
-               public virtual Type[] GetGenericArguments ()
-               {
-                       throw new NotSupportedException ();
-               }
-
-               public virtual bool ContainsGenericParameters {
-                       get { return false; }
-               }
-
-               public virtual extern bool IsGenericTypeDefinition {
-                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
-                       get;
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal extern Type GetGenericTypeDefinition_impl ();
-
-               public virtual Type GetGenericTypeDefinition ()
-               {
-                       throw new NotSupportedException ("Derived classes must provide an implementation.");
-               }
-
-               public virtual extern bool IsGenericType {
-                       [MethodImplAttribute(MethodImplOptions.InternalCall)]
-                       get;
-               }
-               
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               static extern Type MakeGenericType (Type gt, Type [] types);
-
-               public virtual Type MakeGenericType (params Type[] typeArguments)
-               {
-                       if (IsUserType)
-                               throw new NotSupportedException ();
-                       if (!IsGenericTypeDefinition)
-                               throw new InvalidOperationException ("not a generic type definition");
-                       if (typeArguments == null)
-                               throw new ArgumentNullException ("typeArguments");
-                       if (GetGenericArguments().Length != typeArguments.Length)
-                               throw new ArgumentException (String.Format ("The type or method has {0} generic parameter(s) but {1} generic argument(s) where provided. A generic argument must be provided for each generic parameter.", GetGenericArguments ().Length, typeArguments.Length), "typeArguments");
-
-                       bool hasUserType = false;
-
-                       Type[] systemTypes = new Type[typeArguments.Length];
-                       for (int i = 0; i < typeArguments.Length; ++i) {
-                               Type t = typeArguments [i];
-                               if (t == null)
-                                       throw new ArgumentNullException ("typeArguments");
-
-                               if (!(t is MonoType))
-                                       hasUserType = true;
-                               systemTypes [i] = t;
-                       }
-
-                       if (hasUserType) {
-#if FULL_AOT_RUNTIME
-                               throw new NotSupportedException ("User types are not supported under full aot");
-#else
-                               return new MonoGenericClass (this, typeArguments);
-#endif
-                       }
-
-                       Type res = MakeGenericType (this, systemTypes);
-                       if (res == null)
-                               throw new TypeLoadException ();
-                       return res;
-               }
-
-               public virtual bool IsGenericParameter {
-                       get {
-                               return false;
-                       }
-               }
-
-               public bool IsNested {
-                       get {
-                               return DeclaringType != null;
-                       }
-               }
-
-               public bool IsVisible {
-                       get {
-                               if (IsNestedPublic)
-                                       return DeclaringType.IsVisible;
-
-                               return IsPublic;
-                       }
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern int GetGenericParameterPosition ();
-               
-               public virtual int GenericParameterPosition {
-                       get {
-                               int res = GetGenericParameterPosition ();
-                               if (res < 0)
-                                       throw new InvalidOperationException ();
-                               return res;
-                       }
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern GenericParameterAttributes GetGenericParameterAttributes ();
-
-               public virtual GenericParameterAttributes GenericParameterAttributes {
-                       get {
-                               if (!IsSystemType)
-                                       throw new NotSupportedException ("Derived classes must provide an implementation.");
-
-                               if (!IsGenericParameter)
-                                       throw new InvalidOperationException ();
-
-                               return GetGenericParameterAttributes ();
-                       }
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern Type[] GetGenericParameterConstraints_impl ();
-
-               public virtual Type[] GetGenericParameterConstraints ()
-               {
-                       if (!IsSystemType)
-                               throw new InvalidOperationException ();
-
-                       if (!IsGenericParameter)
-                               throw new InvalidOperationException ();
-
-                       return GetGenericParameterConstraints_impl ();
-               }
-
-               public virtual MethodBase DeclaringMethod {
-                       get {
-                               return null;
-                       }
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern Type make_array_type (int rank);
-
-               public virtual Type MakeArrayType ()
-               {
-                       if (!IsSystemType)
-                               throw new NotSupportedException ("Derived classes must provide an implementation.");
-                       return make_array_type (0);
-               }
-
-               public virtual Type MakeArrayType (int rank)
-               {
-                       if (!IsSystemType)
-                               throw new NotSupportedException ("Derived classes must provide an implementation.");
-                       if (rank < 1 || rank > 255)
-                               throw new IndexOutOfRangeException ();
-                       return make_array_type (rank);
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern Type make_byref_type ();
-
-               public virtual Type MakeByRefType ()
-               {
-                       if (!IsSystemType)
-                               throw new NotSupportedException ("Derived classes must provide an implementation.");
-                       if (IsByRef)
-                               throw new TypeLoadException ("Can not call MakeByRefType on a ByRef type");
-                       return make_byref_type ();
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               static extern Type MakePointerType (Type type);
-
-               public virtual Type MakePointerType ()
-               {
-                       if (!IsSystemType)
-                               throw new NotSupportedException ("Derived classes must provide an implementation.");
-                       return MakePointerType (this);
-               }
-
-               public static Type ReflectionOnlyGetType (string typeName, 
-                                                         bool throwIfNotFound, 
-                                                         bool ignoreCase)
-               {
-                       if (typeName == null)
-                               throw new ArgumentNullException ("typeName");
-                       int idx = typeName.IndexOf (',');
-                       if (idx < 0 || idx == 0 || idx == typeName.Length - 1)
-                               throw new ArgumentException ("Assembly qualifed type name is required", "typeName");
-                       string an = typeName.Substring (idx + 1);
-                       Assembly a;
-                       try {
-                               a = Assembly.ReflectionOnlyLoad (an);
-                       } catch {
-                               if (throwIfNotFound)
-                                       throw;
-                               return null;
-                       }
-                       return a.GetType (typeName.Substring (0, idx), throwIfNotFound, ignoreCase);
-               }
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern void GetPacking (out int packing, out int size);         
-
-               public virtual StructLayoutAttribute StructLayoutAttribute {
-                       get {
-                               throw new NotSupportedException ();
-                       }
-               }
-               
-               internal StructLayoutAttribute GetStructLayoutAttribute ()
-               {
-                       LayoutKind kind;
-
-                       if (IsLayoutSequential)
-                               kind = LayoutKind.Sequential;
-                       else if (IsExplicitLayout)
-                               kind = LayoutKind.Explicit;
-                       else
-                               kind = LayoutKind.Auto;
-
-                       StructLayoutAttribute attr = new StructLayoutAttribute (kind);
-
-                       if (IsUnicodeClass)
-                               attr.CharSet = CharSet.Unicode;
-                       else if (IsAnsiClass)
-                               attr.CharSet = CharSet.Ansi;
-                       else
-                               attr.CharSet = CharSet.Auto;
-
-                       if (kind != LayoutKind.Auto) {
-                               int packing;
-                               GetPacking (out packing, out attr.Size);
-                               // 0 means no data provided, we end up with default value
-                               if (packing != 0)
-                                       attr.Pack = packing;
-                       }
-
-                       return attr;
-               }
-
-               internal object[] GetPseudoCustomAttributes ()
-               {
-                       int count = 0;
-
-                       /* IsSerializable returns true for delegates/enums as well */
-                       if ((Attributes & TypeAttributes.Serializable) != 0)
-                               count ++;
-                       if ((Attributes & TypeAttributes.Import) != 0)
-                               count ++;
-
-                       if (count == 0)
-                               return null;
-                       object[] attrs = new object [count];
-                       count = 0;
-
-                       if ((Attributes & TypeAttributes.Serializable) != 0)
-                               attrs [count ++] = new SerializableAttribute ();
-                       if ((Attributes & TypeAttributes.Import) != 0)
-                               attrs [count ++] = new ComImportAttribute ();
-
-                       return attrs;
-               }                       
-
-
-               public virtual bool IsEquivalentTo (Type other)
-               {
-                       return this == other;
-               }
-
-               /* 
-                * Return whenever this object is an instance of a user defined subclass
-                * of System.Type or an instance of TypeDelegator.
-                * A user defined type is not simply the opposite of a system type.
-                * It's any class that's neither a SRE or runtime baked type.
-                */
-               internal virtual bool IsUserType {
-                       get {
-                               return true;
-                       }
-               }
-
-               internal Type GetRootElementType()
-               {
-                       Type rootElementType = this;
-
-                       while (rootElementType.HasElementType)
-                               rootElementType = rootElementType.GetElementType();
-
-                       return rootElementType;
-               }
-
-        #region Enum methods
-
-        // Default implementations of GetEnumNames, GetEnumValues, and GetEnumUnderlyingType
-        // Subclass of types can override these methods.
-
-        public virtual string[] GetEnumNames()
-        {
-            if (!IsEnum)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
-            Contract.Ensures(Contract.Result<String[]>() != null);
-
-            string[] names;
-            Array values;
-            GetEnumData(out names, out values);
-            return names;
-        }
-
-        // We don't support GetEnumValues in the default implementation because we cannot create an array of
-        // a non-runtime type. If there is strong need we can consider returning an object or int64 array.
-        public virtual Array GetEnumValues()
-        {
-            if (!IsEnum)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
-            Contract.Ensures(Contract.Result<Array>() != null);
-
-            throw new NotImplementedException();
-        }
-
-        // Returns the enum values as an object array.
-        private Array GetEnumRawConstantValues()
-        {
-            string[] names;
-            Array values;
-            GetEnumData(out names, out values);
-            return values;
-        }
-
-        // This will return enumValues and enumNames sorted by the values.
-        private void GetEnumData(out string[] enumNames, out Array enumValues)
-        {
-            Contract.Ensures(Contract.ValueAtReturn<String[]>(out enumNames) != null);
-            Contract.Ensures(Contract.ValueAtReturn<Array>(out enumValues) != null);
-
-            FieldInfo[] flds = GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
-
-            object[] values = new object[flds.Length];
-            string[] names = new string[flds.Length];
-
-            for (int i = 0; i < flds.Length; i++)
-            {
-                names[i] = flds[i].Name;
-                values[i] = flds[i].GetRawConstantValue();
-            }
-
-            // Insertion Sort these values in ascending order.
-            // We use this O(n^2) algorithm, but it turns out that most of the time the elements are already in sorted order and
-            // the common case performance will be faster than quick sorting this.
-            IComparer comparer = Comparer.Default;
-            for (int i = 1; i < values.Length; i++)
-            {
-                int j = i;
-                string tempStr = names[i];
-                object val = values[i];
-                bool exchanged = false;
-
-                // Since the elements are sorted we only need to do one comparision, we keep the check for j inside the loop.
-                while (comparer.Compare(values[j - 1], val) > 0)
-                {
-                    names[j] = names[j - 1];
-                    values[j] = values[j - 1];
-                    j--;
-                    exchanged = true;
-                    if (j == 0)
-                        break;
-                }
-
-                if (exchanged)
-                {
-                    names[j] = tempStr;
-                    values[j] = val;
-                }
-            }
-
-            enumNames = names;
-            enumValues = values;
-        }
-
-        public virtual Type GetEnumUnderlyingType()
-        {
-            if (!IsEnum)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
-            Contract.Ensures(Contract.Result<Type>() != null);
-
-            FieldInfo[] fields = GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
-            if (fields == null || fields.Length != 1)
-                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidEnum"), "enumType");
-
-            return fields[0].FieldType;
-        }
-
-        public virtual bool IsEnumDefined(object value)
-        {
-            if (value == null)
-                throw new ArgumentNullException("value");
-
-            if (!IsEnum)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
-            Contract.EndContractBlock();
-
-            // Check if both of them are of the same type
-            Type valueType = value.GetType();
-
-            // If the value is an Enum then we need to extract the underlying value from it
-            if (valueType.IsEnum)
-            {
-                if (!valueType.IsEquivalentTo(this))
-                    throw new ArgumentException(Environment.GetResourceString("Arg_EnumAndObjectMustBeSameType", valueType.ToString(), this.ToString()));
-
-                valueType = valueType.GetEnumUnderlyingType();
-            }
-
-            // If a string is passed in
-            if (valueType == typeof(string))
-            {
-                string[] names = GetEnumNames();
-                if (Array.IndexOf(names, value) >= 0)
-                    return true;
-                else
-                    return false;
-            }
-
-            // If an enum or integer value is passed in
-            if (Type.IsIntegerType(valueType))
-            {
-                Type underlyingType = GetEnumUnderlyingType();
-                // We cannot compare the types directly because valueType is always a runtime type but underlyingType might not be.
-                if (underlyingType.GetTypeCodeImpl() != valueType.GetTypeCodeImpl())
-                    throw new ArgumentException(Environment.GetResourceString("Arg_EnumUnderlyingTypeAndObjectMustBeSameType", valueType.ToString(), underlyingType.ToString()));
-
-                Array values = GetEnumRawConstantValues();
-                return (BinarySearch(values, value) >= 0);
-            }
-            else if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
-            {
-                // if at this point the value type is not an integer type, then its type doesn't match the enum type
-                // NetCF used to throw an argument exception in this case
-                throw new ArgumentException(Environment.GetResourceString("Arg_EnumUnderlyingTypeAndObjectMustBeSameType", valueType.ToString(), GetEnumUnderlyingType()));
-            }
-            else
-            {
-                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_UnknownEnumType"));
-            }
-        }
-
-        public virtual string GetEnumName(object value)
-        {
-            if (value == null)
-                throw new ArgumentNullException("value");
-
-            if (!IsEnum)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
-            Contract.EndContractBlock();
-
-            Type valueType = value.GetType();
-
-            if (!(valueType.IsEnum || Type.IsIntegerType(valueType)))
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), "value");
-
-            Array values = GetEnumRawConstantValues();
-            int index = BinarySearch(values, value);
-
-            if (index >= 0)
-            {
-                string[] names = GetEnumNames();
-                return names[index];
-            }
-
-            return null;
-        }
-
-        // Convert everything to ulong then perform a binary search.
-        private static int BinarySearch(Array array, object value)
-        {
-            ulong[] ulArray = new ulong[array.Length];
-            for (int i = 0; i < array.Length; ++i)
-                ulArray[i] = Enum.ToUInt64(array.GetValue(i));
-
-            ulong ulValue = Enum.ToUInt64(value);
-
-            return Array.BinarySearch(ulArray, ulValue);
-        }
-
-        internal static bool IsIntegerType(Type t)
-        {
-            return (t == typeof(int) ||
-                    t == typeof(short) ||
-                    t == typeof(ushort) ||
-                    t == typeof(byte) ||
-                    t == typeof(sbyte) ||
-                    t == typeof(uint) ||
-                    t == typeof(long) ||
-                    t == typeof(ulong) ||
-                    t == typeof(char) ||
-                    t == typeof(bool));
-        }
-
-        #endregion             
-
-#if !MOBILE
-               void _Type.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               void _Type.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               void _Type.GetTypeInfoCount (out uint pcTInfo)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               void _Type.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
-               {
-                       throw new NotImplementedException ();
-               }
-#endif
-       }
-}
index b1b7cf320f3f5346dd7e01ef4551018929f2d874..b52e42369260330e1b5e71a86c19ea5f4e604068 100644 (file)
@@ -8968,7 +8968,7 @@ namespace MonoTests.System.Reflection.Emit
                        Assert.IsFalse (tb.IsAssignableFrom (typeof (FileStream)), "#C6");
                        Assert.IsTrue (typeof (object).IsAssignableFrom (tb), "#C7");
                        Assert.IsFalse (tb.IsAssignableFrom (typeof (object)), "#C8");
-                       Assert.IsFalse (typeof (IDisposable).IsAssignableFrom (tb), "#C9");
+                       Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb), "#C9");
                        Assert.IsFalse (tb.IsAssignableFrom (typeof (IDisposable)), "#C10");
 
                        Assert.IsTrue (tb.IsAssignableFrom (tb), "#D1");
@@ -8976,13 +8976,13 @@ namespace MonoTests.System.Reflection.Emit
 
                        TypeBuilder tb2 = module.DefineType (genTypeName (),
                                TypeAttributes.Public, tb,
-                               new Type [] { typeof (IAir) });
+                               new Type[] { typeof (IAir) });
 
-                       Assert.IsFalse (typeof (IThrowable).IsAssignableFrom (tb2), "#E1");
+                       Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb2), "#E1");
                        Assert.IsFalse (tb2.IsAssignableFrom (typeof (IThrowable)), "#E2");
-                       Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb2), "#E3");
+                       Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb2), "#E3");
                        Assert.IsFalse (tb2.IsAssignableFrom (typeof (IMoveable)), "#E4");
-                       Assert.IsFalse (typeof (IComparable).IsAssignableFrom (tb2), "#E5");
+                       Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb2), "#E5");
                        Assert.IsFalse (tb2.IsAssignableFrom (typeof (IComparable)), "#E6");
                        Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb2), "#E7");
                        Assert.IsFalse (tb2.IsAssignableFrom (typeof (IAir)), "#E8");
@@ -8991,9 +8991,9 @@ namespace MonoTests.System.Reflection.Emit
                        Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb2), "#E11");
                        Assert.IsFalse (tb2.IsAssignableFrom (typeof (ILiquid)), "#E12");
 
-                       Assert.IsFalse (typeof (Foo).IsAssignableFrom (tb2), "#F1");
+                       Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb2), "#F1");
                        Assert.IsFalse (tb2.IsAssignableFrom (typeof (Foo)), "#F2");
-                       Assert.IsFalse (typeof (Bar).IsAssignableFrom (tb2), "#F3");
+                       Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb2), "#F3");
                        Assert.IsFalse (tb2.IsAssignableFrom (typeof (Bar)), "#F4");
                        Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb2), "#F5");
                        Assert.IsFalse (tb2.IsAssignableFrom (typeof (Baz)), "#F6");
@@ -9006,7 +9006,7 @@ namespace MonoTests.System.Reflection.Emit
                        Assert.IsFalse (tb2.IsAssignableFrom (typeof (FileStream)), "#G6");
                        Assert.IsTrue (typeof (object).IsAssignableFrom (tb2), "#G7");
                        Assert.IsFalse (tb2.IsAssignableFrom (typeof (object)), "#G8");
-                       Assert.IsFalse (typeof (IDisposable).IsAssignableFrom (tb2), "#G9");
+                       Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb2), "#G9");
                        Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDisposable)), "#G10");
 
                        Assert.IsTrue (tb2.IsAssignableFrom (tb2), "#H1");
@@ -9015,24 +9015,24 @@ namespace MonoTests.System.Reflection.Emit
 
                        TypeBuilder tb3 = module.DefineType (genTypeName (),
                                TypeAttributes.Public, tb2,
-                               new Type [] { typeof (IWater) });
+                               new Type[] { typeof (IWater) });
 
-                       Assert.IsFalse (typeof (IThrowable).IsAssignableFrom (tb3), "#I1");
+                       Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb3), "#I1");
                        Assert.IsFalse (tb3.IsAssignableFrom (typeof (IThrowable)), "#I2");
-                       Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb3), "#I3");
+                       Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb3), "#I3");
                        Assert.IsFalse (tb3.IsAssignableFrom (typeof (IMoveable)), "#I4");
-                       Assert.IsFalse (typeof (IComparable).IsAssignableFrom (tb3), "#I5");
+                       Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb3), "#I5");
                        Assert.IsFalse (tb3.IsAssignableFrom (typeof (IComparable)), "#I6");
-                       Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb3), "#I7");
+                       Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb3), "#I7");
                        Assert.IsFalse (tb3.IsAssignableFrom (typeof (IAir)), "#I8");
                        Assert.IsTrue (typeof (IWater).IsAssignableFrom (tb3), "#I9");
                        Assert.IsFalse (tb3.IsAssignableFrom (typeof (IWater)), "#I10");
                        //Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb3), "#I11");
                        Assert.IsFalse (tb3.IsAssignableFrom (typeof (ILiquid)), "#I12");
 
-                       Assert.IsFalse (typeof (Foo).IsAssignableFrom (tb3), "#J1");
+                       Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb3), "#J1");
                        Assert.IsFalse (tb3.IsAssignableFrom (typeof (Foo)), "#J2");
-                       Assert.IsFalse (typeof (Bar).IsAssignableFrom (tb3), "#J3");
+                       Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb3), "#J3");
                        Assert.IsFalse (tb3.IsAssignableFrom (typeof (Bar)), "#J4");
                        Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb3), "#J5");
                        Assert.IsFalse (tb3.IsAssignableFrom (typeof (Baz)), "#J6");
@@ -9045,7 +9045,7 @@ namespace MonoTests.System.Reflection.Emit
                        Assert.IsFalse (tb3.IsAssignableFrom (typeof (FileStream)), "#K6");
                        Assert.IsTrue (typeof (object).IsAssignableFrom (tb3), "#K7");
                        Assert.IsFalse (tb3.IsAssignableFrom (typeof (object)), "#K8");
-                       Assert.IsFalse (typeof (IDisposable).IsAssignableFrom (tb3), "#K9");
+                       Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb3), "#K9");
                        Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDisposable)), "#K10");
 
                        Assert.IsTrue (tb3.IsAssignableFrom (tb3), "#L1");
@@ -9789,13 +9789,13 @@ namespace MonoTests.System.Reflection.Emit
             TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (EmptyIfaceImpl));
                        TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Public, tb);
 
-                       Assert.IsFalse (typeof (EmptyInterface).IsAssignableFrom (tb));
+                       Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb));
                        Type t = tb.CreateType ();
                        Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb));
                        Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t));
                        
                        
-                       Assert.IsFalse (typeof (EmptyInterface).IsAssignableFrom (tb2));
+                       Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb2));
                        Type t2 = tb2.CreateType ();
                        Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb2));
                        Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t2));
index 9d5b93f7b25bf1d5116f5014d8de7ecbbc14bf8a..4f92e8c086b82922e3d4badfc9f6d55bdc292c33 100644 (file)
@@ -3048,8 +3048,7 @@ namespace MonoTests.System
                        Assert.AreEqual (ut, arg, "#B3");
                }
 
-               [Category ("NotWorking")]
-               //We dont support instantiating a user type 
+               [Test]
                public void MakeGenericType_NestedUserDefinedType ()
                {
                        Type ut = new UserType (new UserType (typeof (int)));
@@ -3064,7 +3063,6 @@ namespace MonoTests.System
                }
                
                [Test]
-               [Category ("NotWorking")]
                public void TestMakeGenericType_UserDefinedType_DotNet20SP1 () 
                {
                        Type ut = new UserType(typeof(int));
@@ -3526,10 +3524,10 @@ namespace MonoTests.System
 
                        a.Equals (a);
                        Assert.AreEqual (1, ta.eq, "#1");
-                       Assert.AreEqual (0, ta.ust, "#2");
+                       Assert.AreEqual (2, ta.ust, "#2");
                        a.Equals (b);
                        Assert.AreEqual (2, ta.eq, "#3");
-                       Assert.AreEqual (1, ta.ust, "#4");
+                       Assert.AreEqual (3, ta.ust, "#4");
                        Assert.AreEqual (0, tb.eq, "#5");
                        Assert.AreEqual (1, tb.ust, "#6");
                }
index 944f07987f98f03c0e72ecc79ad085f0d5590444..b64d5a1f761e9c1f39c2ad0de0840e7384ae2119 100644 (file)
@@ -240,7 +240,6 @@ System/TimeZoneInfo.TransitionTime.cs
 System/TimeZoneNotFoundException.cs
 System/TimeoutException.cs
 ../../build/common/MonoTODOAttribute.cs
-System/Type.cs
 System/TypeSpec.cs
 System/TypeAccessException.cs
 System/TypeCode.cs
@@ -1397,8 +1396,10 @@ ReferenceSources/CLRConfig.cs
 ReferenceSources/JitHelpers.cs
 ReferenceSources/EncodingDataItem.cs
 ReferenceSources/EncodingTable.cs
-ReferenceSources/ReflectionOnlyType.cs
+ReferenceSources/TypeNameParser.cs
+ReferenceSources/RuntimeType.cs
 
+../../../external/referencesource/mscorlib/system/__filters.cs
 ../../../external/referencesource/mscorlib/system/__hresults.cs
 ../../../external/referencesource/mscorlib/system/activator.cs
 ../../../external/referencesource/mscorlib/system/AggregateException.cs
@@ -1436,15 +1437,16 @@ ReferenceSources/ReflectionOnlyType.cs
 ../../../external/referencesource/mscorlib/system/sbyte.cs
 ../../../external/referencesource/mscorlib/system/stringcomparer.cs
 ../../../external/referencesource/mscorlib/system/stringfreezingattribute.cs
+../../../external/referencesource/mscorlib/system/rttype.cs
 ../../../external/referencesource/mscorlib/system/timespan.cs
 ../../../external/referencesource/mscorlib/system/throwhelper.cs
 ../../../external/referencesource/mscorlib/system/tuple.cs
+../../../external/referencesource/mscorlib/system/type.cs
 ../../../external/referencesource/mscorlib/system/uint16.cs
 ../../../external/referencesource/mscorlib/system/uint32.cs
 ../../../external/referencesource/mscorlib/system/uint64.cs
 ../../../external/referencesource/mscorlib/system/unityserializationholder.cs
 ../../../external/referencesource/mscorlib/system/version.cs
-
 ../../../external/referencesource/mscorlib/system/collections/arraylist.cs
 ../../../external/referencesource/mscorlib/system/collections/bitarray.cs
 ../../../external/referencesource/mscorlib/system/collections/caseinsensitivecomparer.cs
@@ -1686,4 +1688,4 @@ ReferenceSources/ReflectionOnlyType.cs
 ../../../external/referencesource/mscorlib/system/threading/Tasks/ProducerConsumerQueues.cs
 ../../../external/referencesource/mscorlib/system/threading/Tasks/TaskToApm.cs
 
-
+ReferenceSources/Type.cs
index cf5d13047310a6f61618960edad2e6b39589f255..fb595897837459c99a5bc3fbfcacecd58921f63b 100644 (file)
@@ -402,38 +402,9 @@ ICALL(MCATTR_2, "GetCustomAttributesInternal", custom_attrs_get_by_type)
 ICALL(MCATTR_3, "IsDefinedInternal", custom_attrs_defined_internal)
 
 ICALL_TYPE(MTYPE, "System.MonoType", MTYPE_1)
-ICALL(MTYPE_1, "GetArrayRank", ves_icall_MonoType_GetArrayRank)
-ICALL(MTYPE_2, "GetConstructors", ves_icall_Type_GetConstructors_internal)
-ICALL(MTYPE_3, "GetConstructors_internal", ves_icall_Type_GetConstructors_internal)
-ICALL(MTYPE_4, "GetCorrespondingInflatedConstructor", ves_icall_MonoType_GetCorrespondingInflatedMethod)
-ICALL(MTYPE_5, "GetCorrespondingInflatedMethod", ves_icall_MonoType_GetCorrespondingInflatedMethod)
-ICALL(MTYPE_6, "GetElementType", ves_icall_MonoType_GetElementType)
-ICALL(MTYPE_7, "GetEvents_internal", ves_icall_Type_GetEvents_internal)
-ICALL(MTYPE_8, "GetField", ves_icall_Type_GetField)
-ICALL(MTYPE_9, "GetFields_internal", ves_icall_Type_GetFields_internal)
-ICALL(MTYPE_10, "GetGenericArguments", ves_icall_MonoType_GetGenericArguments)
-ICALL(MTYPE_11, "GetInterfaces", ves_icall_Type_GetInterfaces)
-ICALL(MTYPE_12, "GetMethodsByName", ves_icall_Type_GetMethodsByName)
-ICALL(MTYPE_13, "GetNestedType", ves_icall_Type_GetNestedType)
-ICALL(MTYPE_14, "GetNestedTypes", ves_icall_Type_GetNestedTypes)
-ICALL(MTYPE_15, "GetPropertiesByName", ves_icall_Type_GetPropertiesByName)
-ICALL(MTYPE_16, "InternalGetEvent", ves_icall_MonoType_GetEvent)
-ICALL(MTYPE_17, "IsByRefImpl", ves_icall_type_isbyref)
-ICALL(MTYPE_18, "IsCOMObjectImpl", ves_icall_type_iscomobject)
-ICALL(MTYPE_19, "IsPointerImpl", ves_icall_type_ispointer)
-ICALL(MTYPE_20, "IsPrimitiveImpl", ves_icall_type_isprimitive)
-ICALL(MTYPE_21, "getFullName", ves_icall_System_MonoType_getFullName)
-ICALL(MTYPE_22, "get_Assembly", ves_icall_MonoType_get_Assembly)
-ICALL(MTYPE_23, "get_BaseType", ves_icall_get_type_parent)
-ICALL(MTYPE_24, "get_DeclaringMethod", ves_icall_MonoType_get_DeclaringMethod)
-ICALL(MTYPE_25, "get_DeclaringType", ves_icall_MonoType_get_DeclaringType)
-ICALL(MTYPE_26, "get_IsGenericParameter", ves_icall_MonoType_get_IsGenericParameter)
-ICALL(MTYPE_27, "get_Module", ves_icall_MonoType_get_Module)
-ICALL(MTYPE_28, "get_Name", ves_icall_MonoType_get_Name)
-ICALL(MTYPE_29, "get_Namespace", ves_icall_MonoType_get_Namespace)
-ICALL(MTYPE_31, "get_attributes", ves_icall_get_attributes)
-ICALL(MTYPE_33, "get_core_clr_security_level", vell_icall_MonoType_get_core_clr_security_level)
-ICALL(MTYPE_32, "type_from_obj", mono_type_type_from_obj)
+ICALL(MTYPE_1, "GetCorrespondingInflatedConstructor", ves_icall_MonoType_GetCorrespondingInflatedMethod)
+ICALL(MTYPE_2, "GetCorrespondingInflatedMethod", ves_icall_MonoType_GetCorrespondingInflatedMethod)
+ICALL(MTYPE_3, "type_from_obj", mono_type_type_from_obj)
 
 #ifndef DISABLE_SOCKETS
 ICALL_TYPE(NDNS, "System.Net.Dns", NDNS_1)
@@ -755,6 +726,50 @@ ICALL(MHAN_1, "GetFunctionPointer", ves_icall_RuntimeMethod_GetFunctionPointer)
 
 ICALL_TYPE(RT, "System.RuntimeType", RT_1)
 ICALL(RT_1, "CreateInstanceInternal", ves_icall_System_Activator_CreateInstanceInternal)
+ICALL(RT_2, "GetConstructors_internal", ves_icall_Type_GetConstructors_internal)
+ICALL(RT_3, "GetEvents_internal", ves_icall_Type_GetEvents_internal)
+ICALL(RT_5, "GetFields_internal", ves_icall_Type_GetFields_internal)
+ICALL(RT_6, "GetGenericArguments", ves_icall_MonoType_GetGenericArguments)
+ICALL(RT_7, "GetGenericParameterAttributes", ves_icall_Type_GetGenericParameterAttributes)
+ICALL(RT_8, "GetGenericParameterConstraints_impl", ves_icall_Type_GetGenericParameterConstraints)
+ICALL(RT_9, "GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition)
+ICALL(RT_10, "GetInterfaceMapData", ves_icall_Type_GetInterfaceMapData)
+ICALL(RT_11, "GetInterfaces", ves_icall_Type_GetInterfaces)
+ICALL(RT_12, "GetMethodsByName", ves_icall_Type_GetMethodsByName)
+ICALL(RT_13, "GetNestedTypes_internal", ves_icall_Type_GetNestedTypes)
+ICALL(RT_14, "GetPacking", ves_icall_Type_GetPacking)
+ICALL(RT_15, "GetPropertiesByName", ves_icall_Type_GetPropertiesByName)
+ICALL(RT_16, "GetTypeCodeImplInternal", ves_icall_type_GetTypeCodeInternal)
+ICALL(RT_17, "MakeGenericType", ves_icall_Type_MakeGenericType)
+ICALL(RT_18, "MakePointerType", ves_icall_Type_MakePointerType)
+ICALL(RT_19, "getFullName", ves_icall_System_MonoType_getFullName)
+ICALL(RT_21, "get_DeclaringMethod", ves_icall_MonoType_get_DeclaringMethod)
+ICALL(RT_22, "get_DeclaringType", ves_icall_MonoType_get_DeclaringType)
+ICALL(RT_23, "get_Name", ves_icall_MonoType_get_Name)
+ICALL(RT_24, "get_Namespace", ves_icall_MonoType_get_Namespace)
+ICALL(RT_25, "get_core_clr_security_level", vell_icall_MonoType_get_core_clr_security_level)
+ICALL(RT_26, "make_array_type", ves_icall_Type_make_array_type)
+ICALL(RT_27, "make_byref_type", ves_icall_Type_make_byref_type)
+
+ICALL_TYPE(RTH, "System.RuntimeTypeHandle", RTH_1)
+ICALL(RTH_1, "GetArrayRank", ves_icall_MonoType_GetArrayRank)
+ICALL(RTH_2, "GetAssembly", ves_icall_MonoType_get_Assembly)
+ICALL(RTH_3, "GetAttributes", ves_icall_get_attributes)
+ICALL(RTH_4, "GetBaseType", ves_icall_get_type_parent)
+ICALL(RTH_5, "GetElementType", ves_icall_MonoType_GetElementType)
+ICALL(RTH_6, "GetGenericTypeDefinition_impl", ves_icall_Type_GetGenericTypeDefinition_impl)
+ICALL(RTH_7, "GetMetadataToken", mono_reflection_get_token)
+ICALL(RTH_8, "GetModule", ves_icall_MonoType_get_Module)
+ICALL(RTH_9, "HasInstantiation", ves_icall_Type_get_IsGenericType)
+ICALL(RTH_10, "IsArray", ves_icall_Type_IsArrayImpl)
+ICALL(RTH_11, "IsByRef", ves_icall_type_isbyref)
+ICALL(RTH_12, "IsComObject", ves_icall_type_iscomobject)
+ICALL(RTH_13, "IsGenericTypeDefinition", ves_icall_Type_get_IsGenericTypeDefinition)
+ICALL(RTH_14, "IsGenericVariable", ves_icall_MonoType_get_IsGenericParameter)
+ICALL(RTH_15, "IsInstanceOfType", ves_icall_type_IsInstanceOfType)
+ICALL(RTH_16, "IsPointer", ves_icall_type_ispointer)
+ICALL(RTH_17, "IsPrimitive", ves_icall_type_isprimitive)
+ICALL(RTH_18, "type_is_assignable_from", ves_icall_type_is_assignable_from)
 
 ICALL_TYPE(RNG, "System.Security.Cryptography.RNGCryptoServiceProvider", RNG_1)
 ICALL(RNG_1, "RngClose", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose)
@@ -973,28 +988,8 @@ ICALL(WAITH_3, "WaitAny_internal", ves_icall_System_Threading_WaitHandle_WaitAny
 ICALL(WAITH_4, "WaitOne_internal", ves_icall_System_Threading_WaitHandle_WaitOne_internal)
 
 ICALL_TYPE(TYPE, "System.Type", TYPE_1)
-ICALL(TYPE_1, "EqualsInternal", ves_icall_System_Type_EqualsInternal)
-ICALL(TYPE_2, "GetGenericParameterAttributes", ves_icall_Type_GetGenericParameterAttributes)
-ICALL(TYPE_3, "GetGenericParameterConstraints_impl", ves_icall_Type_GetGenericParameterConstraints)
-ICALL(TYPE_4, "GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition)
-ICALL(TYPE_5, "GetGenericTypeDefinition_impl", ves_icall_Type_GetGenericTypeDefinition_impl)
-ICALL(TYPE_6, "GetInterfaceMapData", ves_icall_Type_GetInterfaceMapData)
-ICALL(TYPE_7, "GetPacking", ves_icall_Type_GetPacking)
-ICALL(TYPE_8, "GetTypeCode", ves_icall_type_GetTypeCodeInternal)
-ICALL(TYPE_9, "GetTypeCodeInternal", ves_icall_type_GetTypeCodeInternal)
-ICALL(TYPE_10, "IsArrayImpl", ves_icall_Type_IsArrayImpl)
-ICALL(TYPE_11, "IsInstanceOfType", ves_icall_type_IsInstanceOfType)
-ICALL(TYPE_12, "MakeGenericType", ves_icall_Type_MakeGenericType)
-ICALL(TYPE_13, "MakePointerType", ves_icall_Type_MakePointerType)
-ICALL(TYPE_14, "get_IsGenericInstance", ves_icall_Type_get_IsGenericInstance)
-ICALL(TYPE_15, "get_IsGenericType", ves_icall_Type_get_IsGenericType)
-ICALL(TYPE_16, "get_IsGenericTypeDefinition", ves_icall_Type_get_IsGenericTypeDefinition)
-ICALL(TYPE_17, "internal_from_handle", ves_icall_type_from_handle)
-ICALL(TYPE_18, "internal_from_name", ves_icall_type_from_name)
-ICALL(TYPE_19, "make_array_type", ves_icall_Type_make_array_type)
-ICALL(TYPE_20, "make_byref_type", ves_icall_Type_make_byref_type)
-ICALL(TYPE_21, "type_is_assignable_from", ves_icall_type_is_assignable_from)
-ICALL(TYPE_22, "type_is_subtype_of", ves_icall_type_is_subtype_of)
+ICALL(TYPE_1, "internal_from_handle", ves_icall_type_from_handle)
+ICALL(TYPE_2, "internal_from_name", ves_icall_type_from_name)
 
 ICALL_TYPE(TYPEDR, "System.TypedReference", TYPEDR_1)
 ICALL(TYPEDR_1, "ToObject",    mono_TypedReference_ToObject)
index fead58e0269a3dddd302f5aa03137477c4185cf1..759c6cec29b721c67b1c178b285a5c74d494fec2 100644 (file)
@@ -1364,15 +1364,6 @@ ves_icall_type_from_handle (MonoType *handle)
        return mono_type_get_object (domain, handle);
 }
 
-ICALL_EXPORT MonoBoolean
-ves_icall_System_Type_EqualsInternal (MonoReflectionType *type, MonoReflectionType *c)
-{
-       if (c && type->type && c->type)
-               return mono_metadata_type_equal (type->type, c->type);
-       else
-               return (type == c) ? TRUE : FALSE;
-}
-
 /* System.TypeCode */
 typedef enum {
        TYPECODE_EMPTY,
@@ -2419,19 +2410,6 @@ ves_icall_Type_MakeGenericType (MonoReflectionType *type, MonoArray *type_array)
        return mono_type_get_object (mono_object_domain (type), geninst);
 }
 
-ICALL_EXPORT gboolean
-ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
-{
-       MonoClass *klass;
-
-       if (type->type->byref)
-               return FALSE;
-
-       klass = mono_class_from_mono_type (type->type);
-
-       return klass->generic_class != NULL;
-}
-
 ICALL_EXPORT gboolean
 ves_icall_Type_get_IsGenericType (MonoReflectionType *type)
 {
@@ -3249,82 +3227,8 @@ enum {
        BFLAGS_OptionalParamBinding = 0x40000
 };
 
-ICALL_EXPORT MonoReflectionField *
-ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
-{
-       MonoDomain *domain; 
-       MonoClass *startklass, *klass;
-       int match;
-       MonoClassField *field;
-       gpointer iter;
-       char *utf8_name;
-       int (*compare_func) (const char *s1, const char *s2) = NULL;
-       domain = ((MonoObject *)type)->vtable->domain;
-       klass = startklass = mono_class_from_mono_type (type->type);
-
-       if (!name) {
-               mono_set_pending_exception (mono_get_exception_argument_null ("name"));
-               return NULL;
-       }
-       if (type->type->byref)
-               return NULL;
-
-       compare_func = (bflags & BFLAGS_IgnoreCase) ? mono_utf8_strcasecmp : strcmp;
-
-handle_parent:
-       if (klass->exception_type != MONO_EXCEPTION_NONE) {
-               mono_set_pending_exception (mono_class_get_exception_for_failure (klass));
-               return NULL;
-       }
-
-       iter = NULL;
-       while ((field = mono_class_get_fields_lazy (klass, &iter))) {
-               guint32 flags = mono_field_get_flags (field);
-               match = 0;
-
-               if (mono_field_is_deleted_with_flags (field, flags))
-                       continue;
-               if ((flags & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
-                       if (bflags & BFLAGS_Public)
-                               match++;
-               } else if ((klass == startklass) || (flags & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) != FIELD_ATTRIBUTE_PRIVATE) {
-                       if (bflags & BFLAGS_NonPublic) {
-                               match++;
-                       }
-               }
-               if (!match)
-                       continue;
-               match = 0;
-               if (flags & FIELD_ATTRIBUTE_STATIC) {
-                       if (bflags & BFLAGS_Static)
-                               if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
-                                       match++;
-               } else {
-                       if (bflags & BFLAGS_Instance)
-                               match++;
-               }
-
-               if (!match)
-                       continue;
-               
-               utf8_name = mono_string_to_utf8 (name);
-
-               if (compare_func (mono_field_get_name (field), utf8_name)) {
-                       g_free (utf8_name);
-                       continue;
-               }
-               g_free (utf8_name);
-               
-               return mono_field_get_object (domain, klass, field);
-       }
-       if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
-               goto handle_parent;
-
-       return NULL;
-}
-
 ICALL_EXPORT MonoArray*
-ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
+ves_icall_Type_GetFields_internal (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoReflectionType *reftype)
 {
        MonoDomain *domain; 
        MonoClass *startklass, *klass, *refklass;
@@ -3332,12 +3236,15 @@ ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, Mon
        MonoObject *member;
        int i, match;
        gpointer iter;
+       char *utf8_name = NULL;
+       int (*compare_func) (const char *s1, const char *s2) = NULL;    
        MonoClassField *field;
        MonoPtrArray tmp_array;
 
        domain = ((MonoObject *)type)->vtable->domain;
        if (type->type->byref)
                return mono_array_new (domain, mono_defaults.field_info_class, 0);
+
        klass = startklass = mono_class_from_mono_type (type->type);
        refklass = mono_class_from_mono_type (reftype->type);
 
@@ -3378,6 +3285,17 @@ handle_parent:
 
                if (!match)
                        continue;
+
+               if (name != NULL) {
+                       if (utf8_name == NULL) {
+                               utf8_name = mono_string_to_utf8 (name);
+                               compare_func = (bflags & BFLAGS_IgnoreCase) ? mono_utf8_strcasecmp : strcmp;
+                       }
+
+                       if (compare_func (mono_field_get_name (field), utf8_name))
+                               continue;
+               }
+
                member = (MonoObject*)mono_field_get_object (domain, refklass, field);
                mono_ptr_array_append (tmp_array, member);
        }
@@ -3391,6 +3309,9 @@ handle_parent:
 
        mono_ptr_array_destroy (tmp_array);
 
+       if (utf8_name != NULL)
+               g_free (utf8_name);
+
        return res;
 }
 
@@ -3794,77 +3715,6 @@ loader_error:
        return NULL;
 }
 
-ICALL_EXPORT MonoReflectionEvent *
-ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
-{
-       MonoDomain *domain;
-       MonoClass *klass, *startklass;
-       gpointer iter;
-       MonoEvent *event;
-       MonoMethod *method;
-       gchar *event_name;
-       int (*compare_func) (const char *s1, const char *s2);
-
-       event_name = mono_string_to_utf8 (name);
-       if (type->type->byref)
-               return NULL;
-       klass = startklass = mono_class_from_mono_type (type->type);
-       domain = mono_object_domain (type);
-
-       mono_class_init_or_throw (klass);
-
-       compare_func = (bflags & BFLAGS_IgnoreCase) ? mono_utf8_strcasecmp : strcmp;
-handle_parent: 
-       if (klass->exception_type != MONO_EXCEPTION_NONE) {
-               mono_set_pending_exception (mono_class_get_exception_for_failure (klass));
-               return NULL;
-       }
-
-       iter = NULL;
-       while ((event = mono_class_get_events (klass, &iter))) {
-               if (compare_func (event->name, event_name))
-                       continue;
-
-               method = event->add;
-               if (!method)
-                       method = event->remove;
-               if (!method)
-                       method = event->raise;
-               if (method) {
-                       if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
-                               if (!(bflags & BFLAGS_Public))
-                                       continue;
-                       } else {
-                               if (!(bflags & BFLAGS_NonPublic))
-                                       continue;
-                               if ((klass != startklass) && (method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PRIVATE)
-                                       continue;
-                       }
-
-                       if (method->flags & METHOD_ATTRIBUTE_STATIC) {
-                               if (!(bflags & BFLAGS_Static))
-                                       continue;
-                               if (!(bflags & BFLAGS_FlattenHierarchy) && (klass != startklass))
-                                       continue;
-                       } else {
-                               if (!(bflags & BFLAGS_Instance))
-                                       continue;
-                       }
-               } else 
-                       if (!(bflags & BFLAGS_NonPublic))
-                               continue;
-               
-               g_free (event_name);
-               return mono_event_get_object (domain, startklass, event);
-       }
-
-       if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
-               goto handle_parent;
-
-       g_free (event_name);
-       return NULL;
-}
-
 static guint
 event_hash (gconstpointer data)
 {
@@ -3881,7 +3731,7 @@ event_equal (MonoEvent *event1, MonoEvent *event2)
 }
 
 ICALL_EXPORT MonoArray*
-ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
+ves_icall_Type_GetEvents_internal (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoReflectionType *reftype)
 {
        MonoException *ex;
        MonoDomain *domain; 
@@ -3892,6 +3742,8 @@ ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, Mon
        MonoEvent *event;
        int i, match;
        gpointer iter;
+       char *utf8_name = NULL;
+       int (*compare_func) (const char *s1, const char *s2) = NULL;    
        GHashTable *events = NULL;
        MonoPtrArray tmp_array;
 
@@ -3952,6 +3804,16 @@ handle_parent:
                if (!match)
                        continue;
 
+               if (name != NULL) {
+                       if (utf8_name == NULL) {
+                               utf8_name = mono_string_to_utf8 (name);
+                               compare_func = (bflags & BFLAGS_IgnoreCase) ? mono_utf8_strcasecmp : strcmp;
+                       }
+
+                       if (compare_func (event->name, utf8_name))
+                               continue;
+               }               
+
                if (g_hash_table_lookup (events, event))
                        continue;
 
@@ -3971,6 +3833,9 @@ handle_parent:
 
        mono_ptr_array_destroy (tmp_array);
 
+       if (utf8_name != NULL)
+               g_free (utf8_name);
+
        return res;
 
 loader_error:
@@ -3985,70 +3850,8 @@ loader_error:
        return NULL;
 }
 
-ICALL_EXPORT MonoReflectionType *
-ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint32 bflags)
-{
-       MonoDomain *domain; 
-       MonoClass *klass;
-       MonoClass *nested;
-       char *str;
-       gpointer iter;
-       
-       if (name == NULL) {
-               mono_set_pending_exception (mono_get_exception_argument_null ("name"));
-               return NULL;
-       }
-       
-       domain = ((MonoObject *)type)->vtable->domain;
-       if (type->type->byref)
-               return NULL;
-       klass = mono_class_from_mono_type (type->type);
-
-       str = mono_string_to_utf8 (name);
-
- handle_parent:
-       if (klass->exception_type != MONO_EXCEPTION_NONE) {
-               mono_set_pending_exception (mono_class_get_exception_for_failure (klass));
-               return NULL;
-       }
-
-       /*
-        * If a nested type is generic, return its generic type definition.
-        * Note that this means that the return value is essentially a
-        * nested type of the generic type definition of @klass.
-        *
-        * A note in MSDN claims that a generic type definition can have
-        * nested types that aren't generic.  In any case, the container of that
-        * nested type would be the generic type definition.
-        */
-       if (klass->generic_class)
-               klass = klass->generic_class->container_class;
-
-       iter = NULL;
-       while ((nested = mono_class_get_nested_types (klass, &iter))) {
-               int match = 0;
-               if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
-                       if (bflags & BFLAGS_Public)
-                               match++;
-               } else {
-                       if (bflags & BFLAGS_NonPublic)
-                               match++;
-               }
-               if (!match)
-                       continue;
-               if (strcmp (nested->name, str) == 0){
-                       g_free (str);
-                       return mono_type_get_object (domain, &nested->byval_arg);
-               }
-       }
-       if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
-               goto handle_parent;
-       g_free (str);
-       return NULL;
-}
-
 ICALL_EXPORT MonoArray*
-ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
+ves_icall_Type_GetNestedTypes (MonoReflectionType *type, MonoString *name, guint32 bflags)
 {
        MonoDomain *domain; 
        MonoClass *klass;
@@ -4057,6 +3860,7 @@ ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
        int i, match;
        MonoClass *nested;
        gpointer iter;
+       char *str = NULL;
        MonoPtrArray tmp_array;
 
        domain = ((MonoObject *)type)->vtable->domain;
@@ -4089,6 +3893,15 @@ ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
                }
                if (!match)
                        continue;
+
+               if (name != NULL) {
+                       if (str == NULL)
+                               str = mono_string_to_utf8 (name);
+
+                       if (strcmp (nested->name, str))
+                               continue;
+               }
+
                member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
                mono_ptr_array_append (tmp_array, member);
        }
@@ -4100,6 +3913,9 @@ ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
 
        mono_ptr_array_destroy (tmp_array);
 
+       if (!str)
+               g_free (str);
+
        return res;
 }