Ver Fonte

[corlib] Type from CoreFX (#11665)

Part of #7737
Maxim Lipnin há 7 anos atrás
pai
commit
5cdc152df8

+ 1 - 1
external/api-snapshot

@@ -1 +1 @@
-Subproject commit 9fa7c78fc869463e110d3e35ec834eb71aaa47e9
+Subproject commit 2216b1c4b0855ca86bf96940b0cc8edf925b3ad6

+ 1 - 1
external/corefx

@@ -1 +1 @@
-Subproject commit 2b478eeab37eb2139aa01fa8e427a298c79bc15e
+Subproject commit 23522c81604a10b529069302173967bbd3fd1675

+ 12 - 5
mcs/class/corlib/Makefile

@@ -217,13 +217,20 @@ satellite_assembly2 = $(test_lib_dir)/nn-NO/$(patsubst %.dll,%.resources.dll,$(t
 
 $(test_lib_output): $(TEST_RESOURCES) $(satellite_assembly1) $(satellite_assembly2) $(test_lib_dir)
 
+mscorlib_for_profile = $(topdir)/class/lib/$(PROFILE)/mscorlib.dll
+
 $(satellite_assembly1): Test/resources/culture-es-ES.cs Test/resources/Resources.es-ES.resources
 	@mkdir -p $(dir $@)
-	$(CSCOMPILE) -target:library -r:$(topdir)/class/lib/$(PROFILE)/mscorlib.dll Test/resources/culture-es-ES.cs -resource:Test/resources/Resources.es-ES.resources -out:$@
+	$(CSCOMPILE) -target:library -r:$(mscorlib_for_profile) Test/resources/culture-es-ES.cs -resource:Test/resources/Resources.es-ES.resources -out:$@
 
 $(satellite_assembly2): Test/resources/culture-nn-NO.cs Test/resources/Resources.nn-NO.resources
 	@mkdir -p $(dir $@)
-	$(CSCOMPILE) -target:library -r:$(topdir)/class/lib/$(PROFILE)/mscorlib.dll Test/resources/culture-nn-NO.cs -resource:Test/resources/Resources.nn-NO.resources -out:$@
+	$(CSCOMPILE) -target:library -r:$(mscorlib_for_profile) Test/resources/culture-nn-NO.cs -resource:Test/resources/Resources.nn-NO.resources -out:$@
+
+test_load_assembly = ${test_lib_dir}/TestLoadAssembly.dll
+
+$(test_load_assembly): ../../../external/corefx/src/System.Runtime/tests/TestLoadAssembly/TestLoadAssembly.cs
+	$(CSCOMPILE) -target:library -r:$(mscorlib_for_profile) -out:${test_lib_dir}/TestLoadAssembly.dll
 
 test_module = $(test_lib_dir)/System.Reflection.TestModule.dll
 
@@ -232,7 +239,7 @@ $(test_module): ../../../external/corefx/src/System.Runtime/tests/TestModule/Sys
 
 XTEST_LIB_FLAGS += -r:$(test_module)
 
-$(xtest_lib_output): $(test_module) $(test_lib_dir)
+$(xtest_lib_output): $(test_load_assembly) $(test_module) $(test_lib_dir)
 
 vtsdir_src = Test/System.Runtime.Serialization.Formatters.Binary/VersionTolerantSerialization
 vtsdir = $(test_lib_dir)/vts
@@ -248,13 +255,13 @@ test-vts: $(vtslibs) $(test_lib_dir)/BinarySerializationOverVersionsTest.dll
 
 $(vtsdir)/%/Address.dll: $(vtsdir_src)/VersionTolerantSerializationTestLib/%/Address.cs
 	@mkdir -p $(dir $@)
-	$(CSCOMPILE) -target:library -warn:0 -r:$(topdir)/class/lib/$(PROFILE)/mscorlib.dll -out:$@ $^
+	$(CSCOMPILE) -target:library -warn:0 -r:$(mscorlib_for_profile) -out:$@ $^
 
 $(test_lib_dir)/BinarySerializationOverVersionsTest.dll: $(vtsdir_src)/BinarySerializationOverVersionsTest.cs $(vtsdir)/1.0/Address.dll $(test_nunit_dep)
 	@mkdir -p $(dir $@)
 	$(CSCOMPILE) $(test_nunit_ref) -warn:0 \
 		-r:$(vtsdir)/1.0/Address.dll \
-		-r:$(topdir)/class/lib/$(PROFILE)/mscorlib.dll \
+		-r:$(mscorlib_for_profile) \
 		-r:$(topdir)/class/lib/$(PROFILE)/System.dll \
 		-target:library \
 		$(vtsdir_src)/BinarySerializationOverVersionsTest.cs -out:$@

+ 2 - 0
mcs/class/corlib/ReferenceSources/RuntimeType.cs

@@ -836,5 +836,7 @@ namespace System
 				return RuntimeTypeHandle.IsByRefLike (this);
 			}
 		}
+
+		public override bool IsTypeDefinition => RuntimeTypeHandle.IsTypeDefinition (this);
 	}
 }

+ 102 - 5
mcs/class/corlib/ReferenceSources/Type.cs

@@ -29,18 +29,15 @@
 using System.Reflection;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
+using StackCrawlMark = System.Threading.StackCrawlMark;
 
 namespace System
 {
+	[Serializable]
 	partial class Type : MemberInfo
 	{
 		internal RuntimeTypeHandle _impl;
 
-		public virtual bool IsTypeDefinition => throw NotImplemented.ByDesign;
-		public virtual bool IsGenericTypeParameter => IsGenericParameter && DeclaringMethod == null;
-		public virtual bool IsGenericMethodParameter => IsGenericParameter && DeclaringMethod != null;
-		public virtual bool IsByRefLike => throw new NotSupportedException(SR.NotSupported_SubclassOverride);        
-
 		internal virtual Type InternalResolve ()
 		{
 			return UnderlyingSystemType;
@@ -85,5 +82,105 @@ namespace System
 
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		static extern Type internal_from_handle (IntPtr handle);
+
+		internal virtual RuntimeTypeHandle GetTypeHandleInternal () => TypeHandle;
+
+#if FEATURE_COMINTEROP || MONO_COM
+		virtual internal bool IsWindowsRuntimeObjectImpl () => throw new NotImplementedException ();
+		virtual internal bool IsExportedToWindowsRuntimeImpl () => throw new NotImplementedException ();
+		internal bool IsWindowsRuntimeObject => IsWindowsRuntimeObjectImpl ();
+		internal bool IsExportedToWindowsRuntime => IsExportedToWindowsRuntimeImpl ();
+#endif // FEATURE_COMINTEROP
+
+		internal virtual bool HasProxyAttributeImpl () => false;
+
+		internal virtual bool IsSzArray => false;
+
+        // This is only ever called on RuntimeType objects.
+        internal string FormatTypeName () => FormatTypeName (false);
+
+		internal virtual string FormatTypeName (bool serialization) => throw new NotImplementedException();
+
+		public bool IsInterface {
+			get {
+				RuntimeType rt = this as RuntimeType;
+				if (rt != null)
+					return RuntimeTypeHandle.IsInterface (rt);
+				return ((GetAttributeFlagsImpl() & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface);
+			}
+		}
+
+		[MethodImplAttribute (MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
+		public static Type GetType (String typeName, bool throwOnError, bool ignoreCase)
+		{
+			StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+			return RuntimeType.GetType (typeName, throwOnError, ignoreCase, false, ref stackMark);
+		}
+ 
+		[MethodImplAttribute (MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
+		public static Type GetType (String typeName, bool throwOnError)
+		{
+			StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+			return RuntimeType.GetType (typeName, throwOnError, false, false, ref stackMark);
+		}
+ 
+		[MethodImplAttribute (MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
+		public static Type GetType (String typeName) {
+			StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+			return RuntimeType.GetType (typeName, false, false, false, ref stackMark);
+		}
+
+		// Methods containing StackCrawlMark local var has to be marked non-inlineable
+		[MethodImplAttribute (MethodImplOptions.NoInlining)] 
+		public static Type GetType (
+			string typeName,
+			Func<AssemblyName, Assembly> assemblyResolver,
+			Func<Assembly, string, bool, Type> typeResolver)
+		{
+			StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+			return TypeNameParser.GetType (typeName, assemblyResolver, typeResolver, false, false, ref stackMark);
+		}
+
+		// Methods containing StackCrawlMark local var has to be marked non-inlineable
+		[MethodImplAttribute (MethodImplOptions.NoInlining)] 
+		public static Type GetType (
+			string typeName,
+			Func<AssemblyName, Assembly> assemblyResolver,
+			Func<Assembly, string, bool, Type> typeResolver,
+			bool throwOnError)
+		{
+			StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+			return TypeNameParser.GetType (typeName, assemblyResolver, typeResolver, throwOnError, false, ref stackMark);
+		}
+
+		// Methods containing StackCrawlMark local var has to be marked non-inlineable
+		[MethodImplAttribute (MethodImplOptions.NoInlining)] 
+		public static Type GetType(
+			string typeName,
+			Func<AssemblyName, Assembly> assemblyResolver,
+			Func<Assembly, string, bool, Type> typeResolver,
+			bool throwOnError,
+			bool ignoreCase)
+		{
+			StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+			return TypeNameParser.GetType (typeName, assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark);
+		}
+
+		public static bool operator == (Type left, Type right)
+		{
+			return object.ReferenceEquals (left, right);
+		}
+
+		public static bool operator != (Type left, Type right)
+		{
+			return !object.ReferenceEquals (left, right);
+		}
+
+        [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
+        public static Type ReflectionOnlyGetType (String typeName, bool throwIfNotFound, bool ignoreCase) 
+        {
+            StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+            return RuntimeType.GetType (typeName, throwIfNotFound, ignoreCase, true /*reflectionOnly*/, ref stackMark);
+        }
 	}
 }

+ 1 - 0
mcs/class/corlib/System.Reflection.Emit/EnumBuilder.cs

@@ -441,6 +441,7 @@ namespace System.Reflection.Emit {
 			return base.IsAssignableFrom (typeInfo);
 		}
 
+		public override bool IsTypeDefinition => true;
 	}
 }
 #endif

+ 2 - 0
mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs

@@ -2027,6 +2027,8 @@ namespace System.Reflection.Emit
 		{
 			throw new ArgumentException("Constant does not match the defined type.");
 		}
+
+		public override bool IsTypeDefinition => true;
 	}
 }
 #endif

+ 4 - 0
mcs/class/corlib/System.Reflection.Emit/TypeBuilderInstantiation.cs

@@ -490,6 +490,10 @@ namespace System.Reflection.Emit
 		{
 			return new TypeBuilderInstantiation (type, typeArguments);
 		}
+
+		public override bool IsTypeDefinition => false;
+
+		public override bool IsConstructedGenericType => true;
 	}
 }
 #else

+ 22 - 0
mcs/class/corlib/System/RuntimeTypeHandle.cs

@@ -262,6 +262,28 @@ namespace System
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		internal extern static bool IsByRefLike (RuntimeType type);
 
+		internal static bool IsTypeDefinition (RuntimeType type)
+		{
+			// That's how it has been done on CoreFX but we have no GetCorElementType method implementation
+			// see https://github.com/dotnet/coreclr/pull/11355
+
+			// CorElementType corElemType = GetCorElementType (type);
+			// if (!((corElemType >= CorElementType.Void && corElemType < CorElementType.Ptr) ||
+			// 		corElemType == CorElementType.ValueType ||
+			// 		corElemType == CorElementType.Class ||
+			// 		corElemType == CorElementType.TypedByRef ||
+			// 		corElemType == CorElementType.I ||
+			// 		corElemType == CorElementType.U ||
+			// 		corElemType == CorElementType.Object))
+			// 	return false;
+			// if (HasInstantiation (type) && !IsGenericTypeDefinition (type))
+			// 	return false;
+			// return true;
+
+			// It's like a workaround mentioned in https://github.com/dotnet/corefx/issues/17345
+			return !type.HasElementType && !type.IsConstructedGenericType && !type.IsGenericParameter;
+		}		
+
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		static extern RuntimeType internal_from_name (string name, ref StackCrawlMark stackMark, Assembly callerAssembly, bool throwOnError, bool ignoreCase, bool reflectionOnly);
 

+ 181 - 0
mcs/class/corlib/corefx/DefaultBinder.cs

@@ -0,0 +1,181 @@
+using System.Reflection;
+
+namespace System {
+	partial class DefaultBinder {
+		internal static bool CompareMethodSig (MethodBase m1, MethodBase m2)
+		{
+			ParameterInfo[] params1 = m1.GetParametersNoCopy ();
+			ParameterInfo[] params2 = m2.GetParametersNoCopy ();
+
+			if (params1.Length != params2.Length)
+				return false;
+
+			int numParams = params1.Length;
+			for (int i = 0; i < numParams; i++) {
+				if (params1 [i].ParameterType != params2 [i].ParameterType)
+					return false;
+			}
+
+			return true;
+		}
+
+        // Given a set of methods that match the base criteria, select a method based
+        // upon an array of types.  This method should return null if no method matchs
+        // the criteria.
+        public sealed override MethodBase SelectMethod (BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
+        {
+            int i;
+            int j;
+
+            Type[] realTypes = new Type [types.Length];
+            for (i = 0; i < types.Length; i++)
+            {
+                realTypes[i] = types[i].UnderlyingSystemType;
+                if (!(realTypes[i].IsRuntimeImplemented() || realTypes[i] is SignatureType))
+                    throw new ArgumentException(SR.Arg_MustBeType, nameof(types));
+            }
+            types = realTypes;
+
+            // We don't automatically jump out on exact match.
+            if (match == null || match.Length == 0)
+                throw new ArgumentException(SR.Arg_EmptyArray, nameof(match));
+
+            MethodBase[] candidates = (MethodBase[])match.Clone();
+
+            // Find all the methods that can be described by the types parameter. 
+            //  Remove all of them that cannot.
+            int CurIdx = 0;
+            for (i = 0; i < candidates.Length; i++)
+            {
+                ParameterInfo[] par = candidates[i].GetParametersNoCopy();
+                if (par.Length != types.Length)
+                    continue;
+                for (j = 0; j < types.Length; j++)
+                {
+                    Type pCls = par[j].ParameterType;
+                    if (types[j].MatchesParameterTypeExactly(par[j]))
+                        continue;
+                    if (pCls == typeof(object))
+                        continue;
+
+                    Type type = types[j];
+                    if (type is SignatureType signatureType)
+                    {
+                        if (!(candidates[i] is MethodInfo methodInfo))
+                            break;
+                        type = signatureType.TryResolveAgainstGenericMethod(methodInfo);
+                        if (type == null)
+                            break;
+                    }
+
+                    if (pCls.IsPrimitive)
+                    {
+                        if (!(type.UnderlyingSystemType.IsRuntimeImplemented()) ||
+                            !CanChangePrimitive(type.UnderlyingSystemType, pCls.UnderlyingSystemType))
+                            break;
+                    }
+                    else
+                    {
+                        if (!pCls.IsAssignableFrom(type))
+                            break;
+                    }
+                }
+                if (j == types.Length)
+                    candidates[CurIdx++] = candidates[i];
+            }
+            if (CurIdx == 0)
+                return null;
+            if (CurIdx == 1)
+                return candidates[0];
+
+            // Walk all of the methods looking the most specific method to invoke
+            int currentMin = 0;
+            bool ambig = false;
+            int[] paramOrder = new int[types.Length];
+            for (i = 0; i < types.Length; i++)
+                paramOrder[i] = i;
+            for (i = 1; i < CurIdx; i++)
+            {
+                int newMin = FindMostSpecificMethod(candidates[currentMin], paramOrder, null, candidates[i], paramOrder, null, types, null);
+                if (newMin == 0)
+                    ambig = true;
+                else
+                {
+                    if (newMin == 2)
+                    {
+                        currentMin = i;
+                        ambig = false;
+                        currentMin = i;
+                    }
+                }
+            }
+            if (ambig)
+                throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
+            return candidates[currentMin];
+        }
+
+        // CanChangePrimitive
+        // This will determine if the source can be converted to the target type
+        private static bool CanChangePrimitive(Type source, Type target)
+        {
+            return CanPrimitiveWiden(source, target);
+        }
+
+        // CanChangePrimitiveObjectToType
+        private static bool CanChangePrimitiveObjectToType(object source, Type type)
+        {
+            return CanPrimitiveWiden(source.GetType(), type);
+        }
+
+        private static bool CanPrimitiveWiden(Type source, Type target)
+        {
+            Primitives widerCodes = _primitiveConversions[(int)(Type.GetTypeCode(source))];
+            Primitives targetCode = (Primitives)(1 << (int)(Type.GetTypeCode(target)));
+
+            return 0 != (widerCodes & targetCode);
+        }
+
+        [Flags]
+        private enum Primitives
+        {
+            Boolean = 1 << (int)TypeCode.Boolean,
+            Char = 1 << (int)TypeCode.Char,
+            SByte = 1 << (int)TypeCode.SByte,
+            Byte = 1 << (int)TypeCode.Byte,
+            Int16 = 1 << (int)TypeCode.Int16,
+            UInt16 = 1 << (int)TypeCode.UInt16,
+            Int32 = 1 << (int)TypeCode.Int32,
+            UInt32 = 1 << (int)TypeCode.UInt32,
+            Int64 = 1 << (int)TypeCode.Int64,
+            UInt64 = 1 << (int)TypeCode.UInt64,
+            Single = 1 << (int)TypeCode.Single,
+            Double = 1 << (int)TypeCode.Double,
+            Decimal = 1 << (int)TypeCode.Decimal,
+            DateTime = 1 << (int)TypeCode.DateTime,
+            String = 1 << (int)TypeCode.String,
+        }
+
+        private static Primitives[] _primitiveConversions = new Primitives[]
+        {
+                /* Empty    */  0, // not primitive
+                /* Object   */  0, // not primitive
+                /* DBNull   */  0, // not exposed.
+                /* Boolean  */  Primitives.Boolean,
+                /* Char     */  Primitives.Char    | Primitives.UInt16 | Primitives.UInt32 | Primitives.Int32  | Primitives.UInt64 | Primitives.Int64  | Primitives.Single |  Primitives.Double,
+                /* SByte    */  Primitives.SByte   | Primitives.Int16  | Primitives.Int32  | Primitives.Int64  | Primitives.Single | Primitives.Double,
+                /* Byte     */  Primitives.Byte    | Primitives.Char   | Primitives.UInt16 | Primitives.Int16  | Primitives.UInt32 | Primitives.Int32  | Primitives.UInt64 |  Primitives.Int64 |  Primitives.Single |  Primitives.Double,
+                /* Int16    */  Primitives.Int16   | Primitives.Int32  | Primitives.Int64  | Primitives.Single | Primitives.Double,
+                /* UInt16   */  Primitives.UInt16  | Primitives.UInt32 | Primitives.Int32  | Primitives.UInt64 | Primitives.Int64  | Primitives.Single | Primitives.Double,
+                /* Int32    */  Primitives.Int32   | Primitives.Int64  | Primitives.Single | Primitives.Double,
+                /* UInt32   */  Primitives.UInt32  | Primitives.UInt64 | Primitives.Int64  | Primitives.Single | Primitives.Double,
+                /* Int64    */  Primitives.Int64   | Primitives.Single | Primitives.Double,
+                /* UInt64   */  Primitives.UInt64  | Primitives.Single | Primitives.Double,
+                /* Single   */  Primitives.Single  | Primitives.Double,
+                /* Double   */  Primitives.Double,
+                /* Decimal  */  Primitives.Decimal,
+                /* DateTime */  Primitives.DateTime,
+                /* [Unused] */  0,
+                /* String   */  Primitives.String,
+        };        		
+	}
+}

+ 5 - 0
mcs/class/corlib/corefx/MethodInfo.cs

@@ -0,0 +1,5 @@
+namespace System.Reflection {
+    partial class MethodInfo {
+        internal virtual int GenericParameterCount => GetGenericArguments ().Length;
+    }
+}

+ 86 - 0
mcs/class/corlib/corert/RtType.cs

@@ -0,0 +1,86 @@
+using System;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+namespace System {
+	partial class RuntimeType {
+		private const int GenericParameterCountAny = -1;
+
+		protected override MethodInfo GetMethodImpl (
+			String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv,
+			Type [] types, ParameterModifier [] modifiers)
+		{
+			return GetMethodImplCommon (name, GenericParameterCountAny, bindingAttr, binder, callConv, types, modifiers);
+		}
+
+		protected override MethodInfo GetMethodImpl (
+			String name, int genericParameterCount, BindingFlags bindingAttr, Binder binder, CallingConventions callConv,
+			Type [] types, ParameterModifier [] modifiers)
+		{
+			return GetMethodImplCommon (name, genericParameterCount, bindingAttr, binder, callConv, types, modifiers);
+		}
+
+		private MethodInfo GetMethodImplCommon (
+			String name, int genericParameterCount, BindingFlags bindingAttr, Binder binder, CallingConventions callConv,
+			Type [] types, ParameterModifier [] modifiers)
+		{
+			ListBuilder<MethodInfo> candidates = GetMethodCandidates (name, genericParameterCount, bindingAttr, callConv, types, false);
+
+			if (candidates.Count == 0)
+				return null;
+
+			if (types == null || types.Length == 0) {
+				MethodInfo firstCandidate = candidates[0];
+
+				if (candidates.Count == 1) {
+					return firstCandidate;
+				} else if (types == null) {
+					for (int j = 1; j < candidates.Count; j++) {
+						MethodInfo methodInfo = candidates [j];
+						if (!System.DefaultBinder.CompareMethodSig (methodInfo, firstCandidate))
+							throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
+					}
+
+					// All the methods have the exact same name and sig so return the most derived one.
+					return System.DefaultBinder.FindMostDerivedNewSlotMeth(candidates.ToArray(), candidates.Count) as MethodInfo;
+				}
+			}
+
+			if (binder == null)
+				binder = DefaultBinder;
+
+			return binder.SelectMethod (bindingAttr, candidates.ToArray(), types, modifiers) as MethodInfo;
+		}
+
+		private ListBuilder<MethodInfo> GetMethodCandidates(
+			String name, int genericParameterCount, BindingFlags bindingAttr, CallingConventions callConv,
+			Type[] types, bool allowPrefixLookup)
+		{
+			bool prefixLookup, ignoreCase;
+			MemberListType listType;
+			RuntimeType.FilterHelper(bindingAttr, ref name, allowPrefixLookup, out prefixLookup, out ignoreCase, out listType);
+
+#if MONO
+			RuntimeMethodInfo[] cache = GetMethodsByName (name, bindingAttr, listType, this);
+#else
+			RuntimeMethodInfo[] cache = Cache.GetMethodList(listType, name);
+#endif
+
+			ListBuilder<MethodInfo> candidates = new ListBuilder<MethodInfo>(cache.Length);
+			for (int i = 0; i < cache.Length; i++)
+			{
+				RuntimeMethodInfo methodInfo = cache[i];
+				if (genericParameterCount != GenericParameterCountAny && genericParameterCount != methodInfo.GenericParameterCount)
+					continue;
+
+				if (FilterApplyMethodInfo(methodInfo, bindingAttr, callConv, types) &&
+					(!prefixLookup || RuntimeType.FilterApplyPrefixLookup(methodInfo, name, ignoreCase)))
+				{
+					candidates.Add(methodInfo);
+				}
+			}
+
+			return candidates;
+		}
+	}
+}

+ 10 - 8
mcs/class/corlib/corert/Type.cs

@@ -2,7 +2,10 @@ using System.Reflection;
 
 namespace System {
 	partial class Type {
-        	internal const string DefaultTypeNameWhenMissingMetadata = "UnknownType";		
+		public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError) => RuntimeType.GetTypeFromCLSIDImpl (clsid, server, throwOnError);
+		public static Type GetTypeFromProgID (string progID, string server, bool throwOnError) => RuntimeType.GetTypeFromProgID (progID, server, throwOnError);
+
+		internal const string DefaultTypeNameWhenMissingMetadata = "UnknownType";		
 		
 		internal string FullNameOrDefault {
 			get {
@@ -10,7 +13,6 @@ namespace System {
 				// We'll still wrap the call in a try-catch as a failsafe.
 				if (InternalNameIfAvailable == null)
 					return DefaultTypeNameWhenMissingMetadata;
-
 				try {
 					return FullName;
 				} catch (MissingMetadataException) {
@@ -19,21 +21,21 @@ namespace System {
 			}
 		}
 
-		internal bool IsRuntimeImplemented () => true;
-
-		internal virtual string InternalGetNameIfAvailable (ref Type rootCauseForFailure) => Name;		
+		internal bool IsRuntimeImplemented () => this.UnderlyingSystemType is RuntimeType;
 
+		internal virtual string InternalGetNameIfAvailable (ref Type rootCauseForFailure) => Name;
+		
 		internal string InternalNameIfAvailable {
 			get {
 				Type ignore = null;
 				return InternalGetNameIfAvailable (ref ignore);
 			}
 		}
-
-		internal string NameOrDefault {
+		
+ 		internal string NameOrDefault {
 			get  {
 				return InternalNameIfAvailable ?? DefaultTypeNameWhenMissingMetadata;
 			}
 		}
 	}
-}
+}

+ 15 - 1
mcs/class/corlib/corlib.csproj

@@ -484,6 +484,15 @@
     <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\ReflectionTypeLoadException.cs" />
     <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\ResourceAttributes.cs" />
     <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\ResourceLocation.cs" />
+    <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\SignatureArrayType.cs" />
+    <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\SignatureByRefType.cs" />
+    <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\SignatureConstructedGenericType.cs" />
+    <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\SignatureGenericMethodParameterType.cs" />
+    <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\SignatureGenericParameterType.cs" />
+    <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\SignatureHasElementType.cs" />
+    <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\SignaturePointerType.cs" />
+    <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\SignatureType.cs" />
+    <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\SignatureTypeExtensions.cs" />
     <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\TargetException.cs" />
     <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\TargetInvocationException.cs" />
     <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Reflection\TargetParameterCountException.cs" />
@@ -643,6 +652,9 @@
     <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\TimeoutException.cs" />
     <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Tuple.cs" />
     <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\TupleExtensions.cs" />
+    <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Type.Enum.cs" />
+    <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Type.Helpers.cs" />
+    <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\Type.cs" />
     <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\TypeAccessException.cs" />
     <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\TypeCode.cs" />
     <Compile Include="..\..\..\external\corefx\src\Common\src\CoreLib\System\TypeInitializationException.cs" />
@@ -1243,7 +1255,6 @@
     <Compile Include="..\referencesource\mscorlib\system\threading\waithandleExtensions.cs" />
     <Compile Include="..\referencesource\mscorlib\system\throwhelper.cs" />
     <Compile Include="..\referencesource\mscorlib\system\timezoneinfo.cs" />
-    <Compile Include="..\referencesource\mscorlib\system\type.cs" />
     <Compile Include="..\referencesource\mscorlib\system\typedreference.cs" />
     <Compile Include="..\referencesource\mscorlib\system\typeloadexception.cs" />
     <Compile Include="..\referencesource\mscorlib\system\unityserializationholder.cs" />
@@ -2006,7 +2017,9 @@
     <Compile Include="corefx\CompareInfo.cs" />
     <Compile Include="corefx\CurrentSystemTimeZone.cs" />
     <Compile Include="corefx\DateTime.cs" />
+    <Compile Include="corefx\DefaultBinder.cs" />
     <Compile Include="corefx\GlobalizationMode.cs" />
+    <Compile Include="corefx\MethodInfo.cs" />
     <Compile Include="corefx\RuntimeImports.cs" />
     <Compile Include="corefx\SR.cs" />
     <Compile Include="corefx\SR.missing.cs" />
@@ -2020,6 +2033,7 @@
     <Compile Include="corert\DependencyReductionRootAttribute.cs" />
     <Compile Include="corert\EnvironmentAugments.cs" />
     <Compile Include="corert\RelocatedTypeAttribute.cs" />
+    <Compile Include="corert\RtType.cs" />
     <Compile Include="corert\RuntimeAugments.cs" />
     <Compile Include="corert\RuntimeThread.cs" />
     <Compile Include="corert\Task.cs" />

+ 15 - 1
mcs/class/corlib/corlib.dll.sources

@@ -1024,7 +1024,9 @@ coreclr/Math.CoreCLR.cs
 ../referencesource/mscorlib/system/throwhelper.cs
 ../referencesource/mscorlib/system/timezoneinfo.cs
 ../../../external/corefx/src/Common/src/CoreLib/System/TimeZoneNotFoundException.cs
-../referencesource/mscorlib/system/type.cs
+../../../external/corefx/src/Common/src/CoreLib/System/Type.cs
+../../../external/corefx/src/Common/src/CoreLib/System/Type.Enum.cs
+../../../external/corefx/src/Common/src/CoreLib/System/Type.Helpers.cs
 ../../../external/corefx/src/Common/src/CoreLib/System/TypeAccessException.cs
 ../../../external/corefx/src/Common/src/CoreLib/System/TypeInitializationException.cs
 ../referencesource/mscorlib/system/typeloadexception.cs
@@ -1210,6 +1212,15 @@ ReferenceSources/AppContextDefaultValues.cs
 ../../../external/corefx/src/Common/src/CoreLib/System/Reflection/ResourceAttributes.cs
 ../../../external/corefx/src/Common/src/CoreLib/System/Reflection/ResourceLocation.cs
 ../../../external/corefx/src/System.Runtime/src/System/Reflection/RuntimeReflectionExtensions.cs
+../../../external/corefx/src/Common/src/CoreLib/System/Reflection/SignatureArrayType.cs
+../../../external/corefx/src/Common/src/CoreLib/System/Reflection/SignatureByRefType.cs
+../../../external/corefx/src/Common/src/CoreLib/System/Reflection/SignatureConstructedGenericType.cs
+../../../external/corefx/src/Common/src/CoreLib/System/Reflection/SignatureGenericMethodParameterType.cs
+../../../external/corefx/src/Common/src/CoreLib/System/Reflection/SignatureGenericParameterType.cs
+../../../external/corefx/src/Common/src/CoreLib/System/Reflection/SignatureHasElementType.cs
+../../../external/corefx/src/Common/src/CoreLib/System/Reflection/SignaturePointerType.cs
+../../../external/corefx/src/Common/src/CoreLib/System/Reflection/SignatureType.cs
+../../../external/corefx/src/Common/src/CoreLib/System/Reflection/SignatureTypeExtensions.cs
 ../../../external/corefx/src/Common/src/CoreLib/System/Reflection/TargetException.cs
 ../../../external/corefx/src/Common/src/CoreLib/System/Reflection/TargetInvocationException.cs
 ../../../external/corefx/src/Common/src/CoreLib/System/Reflection/TargetParameterCountException.cs
@@ -1589,8 +1600,10 @@ corefx/SynchronizationContext.cs
 corefx/SR.cs
 corefx/SR.missing.cs
 corefx/CompareInfo.cs
+corefx/DefaultBinder.cs
 corefx/GlobalizationMode.cs
 corefx/Interop.GetRandomBytes.Mono.cs
+corefx/MethodInfo.cs
 corefx/RuntimeImports.cs
 corefx/TimeSpanParse.cs
 
@@ -1603,6 +1616,7 @@ corert/Task.cs
 corert/ThreadPool.cs
 corert/ThreadPoolBoundHandle.platformnotsupported.cs
 corert/Type.cs
+corert/RtType.cs
 corert/PreAllocatedOverlapped.platformnotsupported.cs
 corert/RuntimeAugments.cs
 ../../../external/corert/src/Common/src/Interop/Unix/System.Private.CoreLib.Native/Interop.Number.cs

+ 3 - 1
mcs/class/corlib/corlib_xtest.dll.sources

@@ -296,6 +296,8 @@
 ../../../external/corefx/src/System.Runtime/tests/System/SByteTests.netcoreapp.cs
 ../../../external/corefx/src/System.Runtime/tests/System/SingleTests.cs
 #../../../external/corefx/src/System.Runtime/tests/System/SingleTests.netcoreapp.cs
+../../../external/corefx/src/System.Runtime/tests/System/TypeTests.cs
+../../../external/corefx/src/System.Runtime/tests/System/TypeTests.netcoreapp.cs
 ../../../external/corefx/src/System.Runtime/tests/System/UInt16Tests.cs
 ../../../external/corefx/src/System.Runtime/tests/System/UInt16Tests.netcoreapp.cs
 ../../../external/corefx/src/System.Runtime/tests/System/UInt32Tests.cs
@@ -315,7 +317,7 @@
 ../../../external/corefx/src/System.Runtime/tests/System/SystemExceptionTests.cs
 ../../../external/corefx/src/System.Runtime/tests/System/TypeUnloadedExceptionTests.cs
 ../../../external/corefx/src/System.Runtime/tests/System/VersionTests.cs
-../../../external/corefx/src/System.Runtime/tests/System/Reflection/*.cs:CustomAttributeDataTests.cs,MethodBaseTests.cs,MethodBaseTests.netcoreapp.cs,MethodBodyTests.cs,SignatureTypes.netcoreapp.cs,StrongNameKeyPairTests.cs,TypeDelegatorTests.netcoreapp.cs
+../../../external/corefx/src/System.Runtime/tests/System/Reflection/*.cs:CustomAttributeDataTests.cs,MethodBaseTests.cs,MethodBaseTests.netcoreapp.cs,MethodBodyTests.cs,StrongNameKeyPairTests.cs
 ../../../external/corefx/src/System.Runtime/tests/System/Text/*.cs
 ../../../external/corefx/src/System.Runtime/tests/System/Runtime/CompilerServices/*.cs:RuntimeHelpersTests.netcoreapp.cs,ConditionalWeakTableTests.netcoreapp.cs,ConditionalWeakTableTests.cs
 

+ 3 - 1
mcs/class/referencesource/mscorlib/system/defaultbinder.cs

@@ -511,7 +511,8 @@ namespace System {
                 throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
             return candidates[currentMin];
         }
-        
+
+#if !MONO        
         // Given a set of methods that match the base criteria, select a method based
         // upon an array of types.  This method should return null if no method matchs
         // the criteria.
@@ -588,6 +589,7 @@ namespace System {
                 throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
             return candidates[currentMin];
         }
+#endif
         
         // Given a set of properties that match the base criteria, select one.
         [System.Security.SecuritySafeCritical]  // auto-generated

+ 10 - 1
mcs/class/referencesource/mscorlib/system/rttype.cs

@@ -2639,7 +2639,11 @@ namespace System
                             for(int i = 0; i < parameterInfos.Length; i ++)
                             {
                                 // a null argument type implies a null arg which is always a perfect match
+#if MONO                                
+                                if ((object)argumentTypes[i] != null && !argumentTypes[i].MatchesParameterTypeExactly(parameterInfos[i]))
+#else
                                 if ((object)argumentTypes[i] != null && !Object.ReferenceEquals(parameterInfos[i].ParameterType, argumentTypes[i]))
+#endif
                                     return false;
                             }
                         }
@@ -3209,6 +3213,7 @@ namespace System
         #endregion
 
         #region Find XXXInfo
+#if !MONO        
         protected override MethodInfo GetMethodImpl(
             String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, 
             Type[] types, ParameterModifier[] modifiers) 
@@ -3246,7 +3251,7 @@ namespace System
 
             return binder.SelectMethod(bindingAttr, candidates.ToArray(), types, modifiers) as MethodInfo;                  
         }
-
+#endif
 
         protected override ConstructorInfo GetConstructorImpl(
             BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, 
@@ -4259,6 +4264,10 @@ namespace System
 
                 if (rtInstantiationElem == null)
                 {
+#if MONO                    
+                    if (instantiationElem.IsSignatureType)
+                        return MakeGenericSignatureType (this, instantiation);
+#endif
                     Type[] instantiationCopy = new Type[instantiation.Length];
                     for (int iCopy = 0; iCopy < instantiation.Length; iCopy++)
                         instantiationCopy[iCopy] = instantiation[iCopy];