From 8bb64f5b4e2004a91d8dd54256cfc463a39d5e49 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 9 Jan 2024 00:23:08 +0000 Subject: [PATCH] Minor trimming optimizations for authoring (#1396) * Remove unnecessary trimming annotation * Stop using GuidGenerator in Make() methods * Remove incorrect trimming annotations * Skip managed marshaller entirely in Make() methods --- src/WinRT.Runtime/Marshalers.cs | 20 -------------------- src/WinRT.Runtime/ObjectReference.cs | 4 ++-- src/cswinrt/code_writers.h | 3 +-- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/src/WinRT.Runtime/Marshalers.cs b/src/WinRT.Runtime/Marshalers.cs index 25c044b01..6a835ba65 100644 --- a/src/WinRT.Runtime/Marshalers.cs +++ b/src/WinRT.Runtime/Marshalers.cs @@ -1237,11 +1237,6 @@ static class MarshalInspectable< T> { public static IObjectReference CreateMarshaler( -#if NET6_0_OR_GREATER - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] -#elif NET - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] -#endif T o, Guid iid, bool unwrapObject = true) @@ -1267,11 +1262,6 @@ public static IObjectReference CreateMarshaler( } public static IObjectReference CreateMarshaler( -#if NET6_0_OR_GREATER - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] -#elif NET - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] -#endif T o, bool unwrapObject = true) { @@ -1279,11 +1269,6 @@ public static IObjectReference CreateMarshaler( } public static ObjectReferenceValue CreateMarshaler2( -#if NET6_0_OR_GREATER - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] -#elif NET - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] -#endif T o, Guid iid, bool unwrapObject = true) @@ -1309,11 +1294,6 @@ public static ObjectReferenceValue CreateMarshaler2( } public static ObjectReferenceValue CreateMarshaler2( -#if NET6_0_OR_GREATER - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] -#elif NET - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] -#endif T o, bool unwrapObject = true) => CreateMarshaler2(o, InterfaceIIDs.IInspectable_IID, unwrapObject); public static IntPtr GetAbi(IObjectReference objRef) => diff --git a/src/WinRT.Runtime/ObjectReference.cs b/src/WinRT.Runtime/ObjectReference.cs index 5a557ec8b..40efc1eb2 100644 --- a/src/WinRT.Runtime/ObjectReference.cs +++ b/src/WinRT.Runtime/ObjectReference.cs @@ -131,7 +131,7 @@ public ObjectReference As< public unsafe ObjectReference As< #if NET - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicFields)] + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)] #endif T>(Guid iid) { @@ -173,7 +173,7 @@ public int TryAs< public virtual unsafe int TryAs< #if NET - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicFields)] + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)] #endif T>(Guid iid, out ObjectReference objRef) { diff --git a/src/cswinrt/code_writers.h b/src/cswinrt/code_writers.h index 045b91981..4198a286d 100644 --- a/src/cswinrt/code_writers.h +++ b/src/cswinrt/code_writers.h @@ -9647,8 +9647,7 @@ RuntimeHelpers.RunClassConstructor(typeof(%).TypeHandle); public static IntPtr Make() { -using var marshaler = MarshalInspectable<%>.CreateMarshaler(_factory).As(); -return marshaler.GetRef(); + return MarshalInspectable<%>.CreateMarshaler2(_factory, InterfaceIIDs.IActivationFactory_IID).Detach(); } static readonly % _factory = new %();