Skip to content

Commit 796b71b

Browse files
committed
Fix trim warnings in 'TestHost' test projects
1 parent 41f06b8 commit 796b71b

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

src/Projections/Test/TestHost.ProbeByHost.cs

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Reflection;
45
using System.Runtime.InteropServices;
56
using System.Text;
@@ -67,13 +68,17 @@ private static unsafe int Do_Abi_ActivateInstance_0(IntPtr thisPtr, out IntPtr i
6768
return 0;
6869
}
6970
}
70-
internal static ObjectReference<Vftbl> FromAbi(IntPtr thisPtr) => ObjectReference<Vftbl>.FromAbi(thisPtr);
71+
internal static ObjectReference<Vftbl> FromAbi(IntPtr thisPtr) => ObjectReference<Vftbl>.FromAbi(thisPtr, global::WinRT.Interop.IID.IID_IActivationFactory);
7172

7273
public static implicit operator IActivationFactory(IObjectReference obj) => (obj != null) ? new IActivationFactory(obj) : null;
7374
protected readonly ObjectReference<Vftbl> _obj;
7475
public IObjectReference ObjRef { get => _obj; }
7576
public IntPtr ThisPtr => _obj.ThisPtr;
76-
public ObjectReference<I> AsInterface<I>() => _obj.As<I>();
77+
public ObjectReference<I> AsInterface<
78+
#if NET
79+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)]
80+
#endif
81+
I>() => _obj.As<I>();
7782
public A As<A>() => _obj.AsType<A>();
7883
public IActivationFactory(IObjectReference obj) : this(obj.As<Vftbl>()) { }
7984
internal IActivationFactory(ObjectReference<Vftbl> obj)
@@ -114,7 +119,12 @@ internal class ActivationFactory : IActivationFactory
114119
namespace WinRT
115120
{
116121
public static class Module
117-
{
122+
{
123+
#if NET
124+
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor, typeof(TestHost.ProbeByHost))]
125+
[UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "We're manually keeping the target type around.")]
126+
127+
#endif
118128
public static unsafe IntPtr GetActivationFactory(String runtimeClassId)
119129
{
120130
if (string.CompareOrdinal(runtimeClassId, "TestHost.ProbeByHost") == 0)
@@ -138,7 +148,10 @@ public static unsafe IntPtr GetActivationFactory(String runtimeClassId)
138148
namespace TestHost
139149
{
140150
public class ProbeByHost : IStringable
141-
{
151+
{
152+
#if NET
153+
[UnconditionalSuppressMessage("SingleFile", "IL3000", Justification = "We're not publishing this test as single file.")]
154+
#endif
142155
public override string ToString()
143156
{
144157
return new System.IO.FileInfo(Assembly.GetExecutingAssembly().Location).Name;

src/Projections/TestHost.ProbeByClass/TestHost.ProbeByClass.cs

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Reflection;
45
using System.Runtime.InteropServices;
56
using System.Text;
@@ -67,13 +68,17 @@ private static unsafe int Do_Abi_ActivateInstance_0(IntPtr thisPtr, out IntPtr i
6768
return 0;
6869
}
6970
}
70-
internal static ObjectReference<Vftbl> FromAbi(IntPtr thisPtr) => ObjectReference<Vftbl>.FromAbi(thisPtr);
71+
internal static ObjectReference<Vftbl> FromAbi(IntPtr thisPtr) => ObjectReference<Vftbl>.FromAbi(thisPtr, global::WinRT.Interop.IID.IID_IActivationFactory);
7172

7273
public static implicit operator IActivationFactory(IObjectReference obj) => (obj != null) ? new IActivationFactory(obj) : null;
7374
protected readonly ObjectReference<Vftbl> _obj;
7475
public IObjectReference ObjRef { get => _obj; }
7576
public IntPtr ThisPtr => _obj.ThisPtr;
76-
public ObjectReference<I> AsInterface<I>() => _obj.As<I>();
77+
public ObjectReference<I> AsInterface<
78+
#if NET
79+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)]
80+
#endif
81+
I>() => _obj.As<I>();
7782
public A As<A>() => _obj.AsType<A>();
7883
public IActivationFactory(IObjectReference obj) : this(obj.As<Vftbl>()) { }
7984
internal IActivationFactory(ObjectReference<Vftbl> obj)
@@ -114,8 +119,13 @@ internal class ActivationFactory : IActivationFactory
114119
namespace WinRT
115120
{
116121
public static class Module
117-
{
118-
public static unsafe IntPtr GetActivationFactory(String runtimeClassId)
122+
{
123+
#if NET
124+
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor, typeof(TestHost.ProbeByClass))]
125+
[UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "We're manually keeping the target type around.")]
126+
127+
#endif
128+
public static unsafe IntPtr GetActivationFactory(string runtimeClassId)
119129
{
120130
if (string.CompareOrdinal(runtimeClassId, "TestHost.ProbeByClass") == 0)
121131
{
@@ -138,7 +148,10 @@ public static unsafe IntPtr GetActivationFactory(String runtimeClassId)
138148
namespace TestHost
139149
{
140150
public class ProbeByClass : IStringable
141-
{
151+
{
152+
#if NET
153+
[UnconditionalSuppressMessage("SingleFile", "IL3000", Justification = "We're not publishing this test as single file.")]
154+
#endif
142155
public override string ToString()
143156
{
144157
return new System.IO.FileInfo(Assembly.GetExecutingAssembly().Location).Name;

0 commit comments

Comments
 (0)