diff options
author | Jan Kotas <jkotas@microsoft.com> | 2017-05-16 23:13:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-16 23:13:57 +0300 |
commit | 3004f6d4fdb9cde9c3b57f06f22f8cd89a3c5277 (patch) | |
tree | fd99e14955552d0c113a68e7f64ee4bf5293bbd1 /src | |
parent | 2a42a6a9a0dcb8d7ea8e9a61d1db899bb08b46e2 (diff) | |
parent | 6f51764a02f6b99cfee9d22c0da8e7b37e4f1650 (diff) |
Merge pull request #3627 from dotnet/nmirror
Merge nmirror to master
Diffstat (limited to 'src')
4 files changed, 125 insertions, 18 deletions
diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/InteropExtensions.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/InteropExtensions.cs index 749c2a6d7..6cb60e738 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/InteropExtensions.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/InteropExtensions.cs @@ -6,6 +6,7 @@ using System; using System.Runtime.CompilerServices; using System.Collections.Generic; using Internal.Runtime.Augments; +using System.Diagnostics; namespace System.Runtime.InteropServices { @@ -105,6 +106,12 @@ namespace System.Runtime.InteropServices return eeType.IsGenericTypeDefinition; } + public static unsafe int GetGenericArgumentCount(this RuntimeTypeHandle genericTypeDefinitionHandle) + { + Debug.Assert(IsGenericTypeDefinition(genericTypeDefinitionHandle)); + return genericTypeDefinitionHandle.ToEETypePtr().ToPointer()->GenericArgumentCount; + } + public static TKey FindEquivalentKeyUnsafe<TKey, TValue>( this ConditionalWeakTable<TKey, TValue> table, TKey key, diff --git a/src/System.Private.Interop/src/Interop/Interop.WinRT.cs b/src/System.Private.Interop/src/Interop/Interop.WinRT.cs index efe0ea69d..8efc3a500 100644 --- a/src/System.Private.Interop/src/Interop/Interop.WinRT.cs +++ b/src/System.Private.Interop/src/Interop/Interop.WinRT.cs @@ -17,7 +17,7 @@ namespace System.Runtime.InteropServices internal const string CORE_WINRT_STRING = "api-ms-win-core-winrt-string-l1-1-0.dll"; internal const string CORE_WINRT_ERROR1 = "api-ms-win-core-winrt-error-l1-1-1.dll"; internal const string CORE_WINRT_ERROR = "api-ms-win-core-winrt-error-l1-1-0.dll"; - + internal const string CORE_WINRT_TYPERESOLUTION = "api-ms-win-ro-typeresolution-l1-1-0.dll"; } [DllImport(Libraries.CORE_WINRT_STRING)] @@ -68,5 +68,12 @@ namespace System.Runtime.InteropServices [DllImport(Libraries.CORE_WINRT_ERROR1, PreserveSig = true)] [McgGeneratedNativeCallCodeAttribute] internal static extern int RoReportUnhandledError(IntPtr pRestrictedErrorInfo); + + [DllImport(Libraries.CORE_WINRT_TYPERESOLUTION, PreserveSig = true)] + [McgGeneratedNativeCallCodeAttribute] + internal static unsafe extern int RoParseTypeName( + HSTRING typename, + uint * typenamePartsLength, + IntPtr ** typenameParts); } } diff --git a/src/System.Private.Interop/src/Shared/McgMarshal.cs b/src/System.Private.Interop/src/Shared/McgMarshal.cs index 82ad2c338..4e937b77b 100644 --- a/src/System.Private.Interop/src/Shared/McgMarshal.cs +++ b/src/System.Private.Interop/src/Shared/McgMarshal.cs @@ -169,6 +169,15 @@ namespace System.Runtime.InteropServices #endif } + internal static Type TypeNameToType(string nativeTypeName, int nativeTypeKind) + { +#if ENABLE_WINRT + return McgTypeHelpers.TypeNameToType(nativeTypeName, nativeTypeKind, checkTypeKind: false); +#else + throw new NotSupportedException("TypeNameToType"); +#endif + } + public static unsafe void TypeToTypeName( Type type, out HSTRING nativeTypeName, @@ -181,6 +190,24 @@ namespace System.Runtime.InteropServices #endif } + /// <summary> + /// Fetch type name + /// </summary> + /// <param name="typeHandle">type</param> + /// <returns>type name</returns> + internal static string TypeToTypeName(RuntimeTypeHandle typeHandle, out int nativeTypeKind) + { +#if ENABLE_WINRT + TypeKind typekind; + string typeName; + McgTypeHelpers.TypeToTypeName(typeHandle, out typeName, out typekind); + nativeTypeKind = (int)typekind; + return typeName; +#else + throw new NotSupportedException("TypeToTypeName"); +#endif + } + #endregion #region String marshalling @@ -367,9 +394,9 @@ namespace System.Runtime.InteropServices } #endif //ENABLE_WINRT - #endregion +#endregion - #region COM marshalling +#region COM marshalling /// <summary> /// Explicit AddRef for RCWs @@ -868,9 +895,9 @@ namespace System.Runtime.InteropServices #endif } - #endregion +#endregion - #region Testing +#region Testing /// <summary> /// Internal-only method to allow testing of apartment teardown code @@ -909,7 +936,7 @@ namespace System.Runtime.InteropServices return list; } - #endregion +#endregion /// <summary> /// This method returns HR for the exception being thrown. @@ -974,7 +1001,7 @@ namespace System.Runtime.InteropServices #endif } - #region Shared templates +#region Shared templates #if ENABLE_MIN_WINRT public static void CleanupNative<T>(IntPtr pObject) { @@ -988,7 +1015,7 @@ namespace System.Runtime.InteropServices } } #endif - #endregion +#endregion #if ENABLE_MIN_WINRT [MethodImpl(MethodImplOptions.NoInlining)] @@ -1047,7 +1074,7 @@ namespace System.Runtime.InteropServices return obj.GetDynamicAdapter(requestedType, default(RuntimeTypeHandle)); } - #region "PInvoke Delegate" +#region "PInvoke Delegate" public static IntPtr GetStubForPInvokeDelegate(RuntimeTypeHandle delegateType, Delegate dele) { diff --git a/src/System.Private.Interop/src/Shared/McgTypeHelpers.cs b/src/System.Private.Interop/src/Shared/McgTypeHelpers.cs index c6d321f39..8617bb251 100644 --- a/src/System.Private.Interop/src/Shared/McgTypeHelpers.cs +++ b/src/System.Private.Interop/src/Shared/McgTypeHelpers.cs @@ -235,6 +235,43 @@ namespace System.Runtime.InteropServices } } #endif //!CORECLR + + internal static bool IsWinRTPrimitiveType(RuntimeTypeHandle typeHandle, out string typeName) + { + // + // Primitive types + // + for (int i = 0; i < s_wellKnownTypes.Length; i++) + { + if (s_wellKnownTypes[i].TypeHandle.Equals(typeHandle)) + { + typeName = s_wellKnownTypeNames[i]; + return true; + } + } + + typeName = null; + return false; + } + + internal static bool IsWinRTPrimitiveType(string typeName, out RuntimeTypeHandle typeHandle) + { + // + // Primitive types + // + for (int i = 0; i < s_wellKnownTypes.Length; i++) + { + if (s_wellKnownTypeNames[i] == typeName) + { + typeHandle = s_wellKnownTypes[i].TypeHandle; + return true; + } + } + + typeHandle = default(RuntimeTypeHandle); + return false; + } + internal static unsafe void TypeToTypeName( RuntimeTypeHandle typeHandle, out string typeName, @@ -271,6 +308,23 @@ namespace System.Runtime.InteropServices return; } +#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT + if (McgModuleManager.UseDynamicInterop) + { + name = DynamicInteropTypeHelper.GetTypeName(typeHandle, out isWinRT); + if (name != null) + { + typeName = name; + typeKind = + (isWinRT ? + TypeKind.Metadata : + TypeKind.Custom); + + return; + } + } +#endif + // // Handle managed types // @@ -350,7 +404,11 @@ namespace System.Runtime.InteropServices internal static unsafe Type TypeNameToType(HSTRING nativeTypeName, int nativeTypeKind) { string name = McgMarshal.HStringToString(nativeTypeName); + return TypeNameToType(name, nativeTypeKind); + } + internal static unsafe Type TypeNameToType(string name, int nativeTypeKind, bool checkTypeKind = true) + { if (!string.IsNullOrEmpty(name)) { // @@ -360,7 +418,7 @@ namespace System.Runtime.InteropServices { if (s_wellKnownTypeNames[i] == name) { - if (nativeTypeKind != (int)TypeKind.Primitive) + if (checkTypeKind && (nativeTypeKind != (int)TypeKind.Primitive)) throw new ArgumentException(SR.Arg_UnexpectedTypeKind); return s_wellKnownTypes[i]; @@ -384,6 +442,14 @@ namespace System.Runtime.InteropServices bool isWinRT; Type type = McgModuleManager.GetTypeFromName(name, out isWinRT); +#if !RHTESTCL && !CORECLR && !CORERT + if (type == null && McgModuleManager.UseDynamicInterop && nativeTypeKind == (int)TypeKind.Metadata) + { + type = DynamicInteropTypeHelper.GetTypeFromWinRTName(name, nativeTypeKind); + isWinRT = true; + } +#endif + #if !RHTESTCL if (type != null && !type.SupportsReflection()) type = null; @@ -756,7 +822,7 @@ namespace System.Runtime.InteropServices internal static bool IsComClass(this RuntimeTypeHandle handle) { -#if CORECLR +#if CORECLR return InteropExtensions.IsClass(handle); #else return !InteropExtensions.IsInterface(handle) && @@ -784,7 +850,7 @@ namespace System.Runtime.InteropServices #endif } - #region "Interface Data" +#region "Interface Data" internal static bool HasInterfaceData(this RuntimeTypeHandle interfaceType) { int moduleIndex, typeIndex; @@ -949,9 +1015,9 @@ namespace System.Runtime.InteropServices } return default(IntPtr); } - #endregion +#endregion - #region "Class Data" +#region "Class Data" internal static GCPressureRange GetGCPressureRange(this RuntimeTypeHandle classType) { int moduleIndex, classIndex; @@ -1020,9 +1086,9 @@ namespace System.Runtime.InteropServices bool isWinRT; return McgModuleManager.GetTypeName(classType, out isWinRT); } - #endregion +#endregion - #region "Generic Argument Data" +#region "Generic Argument Data" internal static RuntimeTypeHandle GetIteratorType(this RuntimeTypeHandle interfaceType) { McgGenericArgumentMarshalInfo mcgGenericArgumentMarshalInfo; @@ -1088,9 +1154,9 @@ namespace System.Runtime.InteropServices return -1; } - #endregion +#endregion - #region "CCWTemplate Data" +#region "CCWTemplate Data" internal static string GetCCWRuntimeClassName(this RuntimeTypeHandle ccwType) { string ccwRuntimeClassName; |