Add PNSE implementations of unsupported built-in custom marshalers to enable good...
authorJeremy Koritzinsky <jkoritzinsky@gmail.com>
Fri, 7 Dec 2018 17:55:37 +0000 (09:55 -0800)
committerGitHub <noreply@github.com>
Fri, 7 Dec 2018 17:55:37 +0000 (09:55 -0800)
src/System.Private.CoreLib/Resources/Strings.resx
src/System.Private.CoreLib/System.Private.CoreLib.csproj
src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/ExpandoToDispatchExMarshaler.cs [new file with mode: 0644]
src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/TypeToTypeInfoMarshaler.cs [new file with mode: 0644]

index d48b228..ca6171e 100644 (file)
   <data name="PlatformNotSupported_OverlappedIO" xml:space="preserve">
     <value>This API is specific to the way in which Windows handles asynchronous I/O, and is not supported on this platform.</value>
   </data>
+  <data name="PlatformNotSupported_ITypeInfo" xml:space="preserve">
+    <value>Marshalling a System.Type to an unmanaged ITypeInfo or marshalling an ITypeInfo to a System.Type is not supported on this platform.</value>
+  </data>
+  <data name="PlatformNotSupported_IExpando" xml:space="preserve">
+    <value>Marshalling an IDispatchEx to an IReflect or IExpando is not supported on this platform.</value>
+  </data>
   <data name="Policy_CannotLoadSemiTrustAssembliesDuringInit" xml:space="preserve">
     <value>All assemblies loaded as part of AppDomain initialization must be fully trusted.</value>
   </data>
index b9842af..3d53137 100644 (file)
     <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\CustomMarshalers\EnumerableViewOfDispatch.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\CustomMarshalers\EnumeratorToEnumVariantMarshaler.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\CustomMarshalers\EnumeratorViewOfEnumVariant.cs" />
+    <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\CustomMarshalers\ExpandoToDispatchExMarshaler.cs" />
+    <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\CustomMarshalers\TypeToTypeInfoMarshaler.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\DispatchWrapper.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\IDispatch.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\WindowsRuntime\Attributes.cs" />
diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/ExpandoToDispatchExMarshaler.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/ExpandoToDispatchExMarshaler.cs
new file mode 100644 (file)
index 0000000..3cd8292
--- /dev/null
@@ -0,0 +1,47 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Runtime.InteropServices.ComTypes;
+using System.Text;
+
+namespace System.Runtime.InteropServices.CustomMarshalers
+{
+    internal class ExpandoToDispatchExMarshaler : ICustomMarshaler
+    {
+        private static readonly ExpandoToDispatchExMarshaler s_ExpandoToDispatchExMarshaler = new ExpandoToDispatchExMarshaler();
+
+        public static ICustomMarshaler GetInstance(string cookie) => s_ExpandoToDispatchExMarshaler;
+
+        private ExpandoToDispatchExMarshaler()
+        {
+        }
+
+        public void CleanUpManagedData(object ManagedObj)
+        {
+        }
+
+        public void CleanUpNativeData(IntPtr pNativeData)
+        {
+        }
+
+        public int GetNativeDataSize()
+        {
+            // Return -1 to indicate the managed type this marshaler handles is not a value type.
+            return -1;
+        }
+
+        public IntPtr MarshalManagedToNative(object ManagedObj)
+        {
+            throw new PlatformNotSupportedException(SR.PlatformNotSupported_IExpando);
+        }
+
+        public object MarshalNativeToManaged(IntPtr pNativeData)
+        {
+            throw new PlatformNotSupportedException(SR.PlatformNotSupported_IExpando);
+        }
+    }
+}
diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/TypeToTypeInfoMarshaler.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/TypeToTypeInfoMarshaler.cs
new file mode 100644 (file)
index 0000000..eeae079
--- /dev/null
@@ -0,0 +1,47 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Runtime.InteropServices.ComTypes;
+using System.Text;
+
+namespace System.Runtime.InteropServices.CustomMarshalers
+{
+    internal class TypeToTypeInfoMarshaler : ICustomMarshaler
+    {
+        private static readonly TypeToTypeInfoMarshaler s_typeToTypeInfoMarshaler = new TypeToTypeInfoMarshaler();
+
+        public static ICustomMarshaler GetInstance(string cookie) => s_typeToTypeInfoMarshaler;
+
+        private TypeToTypeInfoMarshaler()
+        {
+        }
+
+        public void CleanUpManagedData(object ManagedObj)
+        {
+        }
+
+        public void CleanUpNativeData(IntPtr pNativeData)
+        {
+        }
+
+        public int GetNativeDataSize()
+        {
+            // Return -1 to indicate the managed type this marshaler handles is not a value type.
+            return -1;
+        }
+
+        public IntPtr MarshalManagedToNative(object ManagedObj)
+        {
+            throw new PlatformNotSupportedException(SR.PlatformNotSupported_ITypeInfo);
+        }
+
+        public object MarshalNativeToManaged(IntPtr pNativeData)
+        {
+            throw new PlatformNotSupportedException(SR.PlatformNotSupported_ITypeInfo);
+        }
+    }
+}