Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit non public methods from preserved metadata #1442

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/WinRT.Runtime/ComWrappersSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,25 +439,30 @@ internal static Func<IntPtr, object> CreateDelegateFactory(Type type)

private static Func<IInspectable, object> CreateNullableTFactory(Type implementationType)
{
var getValueMethod = implementationType.GetHelperType().GetMethod("GetValue", BindingFlags.Static | BindingFlags.NonPublic);
var getValueMethod = implementationType.GetHelperType().GetMethod("GetValue", BindingFlags.Static | BindingFlags.Public);
return (IInspectable obj) => getValueMethod.Invoke(null, new[] { obj });
}

private static Func<IInspectable, object> CreateAbiNullableTFactory(
#if NET
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicMethods)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
#endif
Type implementationType)
{
var getValueMethod = implementationType.GetMethod("GetValue", BindingFlags.Static | BindingFlags.NonPublic);
return (IInspectable obj) => getValueMethod.Invoke(null, new[] { obj });
// This method is only called when 'implementationType' has been validated to be some ABI.System.Nullable_Delegate<T>.
// As such, we know that the type definitely has a method with signature 'static Nullable GetValue(IInspectable)'.
var getValueMethod = implementationType.GetMethod("GetValue", BindingFlags.Static | BindingFlags.Public);

return (Func<IInspectable, object>)getValueMethod.CreateDelegate(typeof(Func<IInspectable, object>));
}

private static Func<IInspectable, object> CreateArrayFactory(Type implementationType)
{
var getValueFunc = (Func<IInspectable, object>)implementationType.GetHelperType().GetMethod("GetValue", BindingFlags.Static | BindingFlags.NonPublic).
CreateDelegate(typeof(Func<IInspectable, object>));
return getValueFunc;
// This method is only called when 'implementationType' is some 'Windows.Foundation.IReferenceArray<T>' type.
// That interface is only implemented by 'ABI.Windows.Foundation.IReferenceArray<T>', and the method is public.
var getValueMethod = implementationType.GetHelperType().GetMethod("GetValue", BindingFlags.Static | BindingFlags.Public);

return (Func<IInspectable, object>)getValueMethod.CreateDelegate(typeof(Func<IInspectable, object>));
}

// This is used to hold the reference to the native value type object (IReference) until the actual value in it (boxed as an object) gets cleaned up by GC
Expand All @@ -476,7 +481,7 @@ private static Func<IInspectable, object> CreateReferenceCachingFactory(Func<IIn

private static Func<IInspectable, object> CreateCustomTypeMappingFactory(Type customTypeHelperType)
{
var fromAbiMethod = customTypeHelperType.GetMethod("FromAbi", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
var fromAbiMethod = customTypeHelperType.GetMethod("FromAbi", BindingFlags.Public | BindingFlags.Static);
if (fromAbiMethod is null)
{
throw new MissingMethodException();
Expand Down
9 changes: 4 additions & 5 deletions src/WinRT.Runtime/Marshalers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,8 +1082,7 @@ struct MarshalInterface<T>
DynamicallyAccessedMemberTypes.PublicFields |
DynamicallyAccessedMemberTypes.NonPublicFields |
DynamicallyAccessedMemberTypes.PublicNestedTypes |
DynamicallyAccessedMemberTypes.PublicMethods |
DynamicallyAccessedMemberTypes.NonPublicMethods)]
DynamicallyAccessedMemberTypes.PublicMethods)]
#endif
private static readonly Type HelperType = typeof(T).GetHelperType();
private static Func<T, IObjectReference> _ToAbi;
Expand Down Expand Up @@ -1254,7 +1253,7 @@ public static IObjectReference CreateMarshaler<V>(
Type helperType = Projections.FindCustomHelperTypeMapping(publicType, true);
if (helperType != null)
{
var createMarshaler = helperType.GetMethod("CreateMarshaler", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
var createMarshaler = helperType.GetMethod("CreateMarshaler", BindingFlags.Public | BindingFlags.Static);
return (IObjectReference) createMarshaler.Invoke(null, new[] { (object) o });
}

Expand Down Expand Up @@ -1286,7 +1285,7 @@ public static ObjectReferenceValue CreateMarshaler2(
Type helperType = Projections.FindCustomHelperTypeMapping(publicType, true);
if (helperType != null)
{
var createMarshaler = helperType.GetMethod("CreateMarshaler2", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
var createMarshaler = helperType.GetMethod("CreateMarshaler2", BindingFlags.Public | BindingFlags.Static);
return ((ObjectReferenceValue)createMarshaler.Invoke(null, new[] { (object)o }));
}

Expand Down Expand Up @@ -1547,7 +1546,7 @@ static Marshaler()
if (AbiType != null)
{
// Could still be blittable and the 'ABI.*' type exists for other reasons (e.g. it's a mapped type)
if (AbiType.GetMethod("FromAbi", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static) == null)
if (AbiType.GetMethod("FromAbi", BindingFlags.Public | BindingFlags.Static) == null)
{
AbiType = null;
}
Expand Down
3 changes: 2 additions & 1 deletion src/WinRT.Runtime/MatchingRefApiCompatBaseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ TypesMustExist : Type 'WinRT.StructTypeDetails<T, TAbi>' does not exist in the r
MembersMustExist : Member 'public void WinRT.WindowsRuntimeTypeAttribute..ctor(System.String, System.String)' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.String WinRT.WindowsRuntimeTypeAttribute.GuidSignature.get()' does not exist in the reference but it does exist in the implementation.
TypesMustExist : Type 'WinRT.WinRTExposedTypeAttribute' does not exist in the reference but it does exist in the implementation.
Total Issues: 130
MembersMustExist : Member 'public T ABI.System.Nullable<T>.GetValue(WinRT.IInspectable)' does not exist in the reference but it does exist in the implementation.
Total Issues: 131
4 changes: 0 additions & 4 deletions src/WinRT.Runtime/Projections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public static void RegisterCustomAbiTypeMapping(
#if NET
[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods |
DynamicallyAccessedMemberTypes.NonPublicMethods |
DynamicallyAccessedMemberTypes.PublicNestedTypes |
DynamicallyAccessedMemberTypes.PublicFields)]
#endif
Expand All @@ -141,7 +140,6 @@ private static void RegisterCustomAbiTypeMappingNoLock(
#if NET
[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods |
DynamicallyAccessedMemberTypes.NonPublicMethods |
DynamicallyAccessedMemberTypes.PublicNestedTypes |
DynamicallyAccessedMemberTypes.PublicFields)]
#endif
Expand All @@ -165,7 +163,6 @@ private static void RegisterCustomAbiTypeMappingNoLock(
#if NET
[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods |
DynamicallyAccessedMemberTypes.NonPublicMethods |
DynamicallyAccessedMemberTypes.PublicNestedTypes)]
#endif
Type abiType)
Expand All @@ -177,7 +174,6 @@ private static void RegisterCustomAbiTypeMappingNoLock(
#if NET
[return: DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods |
DynamicallyAccessedMemberTypes.NonPublicMethods |
DynamicallyAccessedMemberTypes.PublicNestedTypes |
DynamicallyAccessedMemberTypes.PublicFields)]
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/Projections/IReferenceArray.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static object FromAbi(IntPtr ptr)
return wrapper.Value;
}

internal static unsafe object GetValue(IInspectable inspectable)
public static unsafe object GetValue(IInspectable inspectable)
{
IntPtr referenceArrayPtr = IntPtr.Zero;
int __retval_length = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static object FromAbi(IntPtr ptr)
return wrapper.Value;
}

internal static object GetValue(IInspectable inspectable)
public static object GetValue(IInspectable inspectable)
{
var array = new IReferenceArray<T>(inspectable.ObjRef);
return array.Value;
Expand Down
42 changes: 21 additions & 21 deletions src/WinRT.Runtime/Projections/Nullable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public Nullable(ObjectReference<Vftbl> obj)
_obj = obj;
}

internal static unsafe T GetValue(IInspectable inspectable)
public static unsafe T GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -571,7 +571,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, int* __return_value
}
}

unsafe internal static int GetValue(IInspectable inspectable)
public static unsafe int GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -648,7 +648,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, IntPtr* __return_va
}
}

unsafe internal static Nullable GetValue(IInspectable inspectable)
public static unsafe Nullable GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
IntPtr __retval = default;
Expand Down Expand Up @@ -726,7 +726,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, byte* __return_valu
}
}

unsafe internal static byte GetValue(IInspectable inspectable)
public static unsafe byte GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -803,7 +803,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, sbyte* __return_val
}
}

unsafe internal static sbyte GetValue(IInspectable inspectable)
public static unsafe sbyte GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -880,7 +880,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, short* __return_val
}
}

unsafe internal static short GetValue(IInspectable inspectable)
public static unsafe short GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -957,7 +957,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, ushort* __return_va
}
}

unsafe internal static ushort GetValue(IInspectable inspectable)
public static unsafe ushort GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -1034,7 +1034,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, uint* __return_valu
}
}

unsafe internal static uint GetValue(IInspectable inspectable)
public static unsafe uint GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -1111,7 +1111,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, long* __return_valu
}
}

unsafe internal static long GetValue(IInspectable inspectable)
public static unsafe long GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -1188,7 +1188,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, ulong* __return_val
}
}

unsafe internal static ulong GetValue(IInspectable inspectable)
public static unsafe ulong GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -1265,7 +1265,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, float* __return_val
}
}

unsafe internal static float GetValue(IInspectable inspectable)
public static unsafe float GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -1342,7 +1342,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, double* __return_va
}
}

unsafe internal static double GetValue(IInspectable inspectable)
public static unsafe double GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -1419,7 +1419,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, char* __return_valu
}
}

unsafe internal static char GetValue(IInspectable inspectable)
public static unsafe char GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -1496,7 +1496,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, bool* __return_valu
}
}

unsafe internal static bool GetValue(IInspectable inspectable)
public static unsafe bool GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -1573,7 +1573,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, Guid* __return_valu
}
}

unsafe internal static Guid GetValue(IInspectable inspectable)
public static unsafe Guid GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
try
Expand Down Expand Up @@ -1650,7 +1650,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, DateTimeOffset* __r
}
}

unsafe internal static global::System.DateTimeOffset GetValue(IInspectable inspectable)
public static unsafe global::System.DateTimeOffset GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
DateTimeOffset __retval = default;
Expand Down Expand Up @@ -1728,7 +1728,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, TimeSpan* __return_
}
}

unsafe internal static global::System.TimeSpan GetValue(IInspectable inspectable)
public static unsafe global::System.TimeSpan GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
TimeSpan __retval = default;
Expand Down Expand Up @@ -1867,7 +1867,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, Type* __return_valu
}
}

unsafe internal static Nullable GetValue(IInspectable inspectable)
public static unsafe Nullable GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
Type __retval = default;
Expand Down Expand Up @@ -1945,7 +1945,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, Exception* __return
}
}

unsafe internal static Nullable GetValue(IInspectable inspectable)
public static unsafe Nullable GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
Exception __retval = default;
Expand Down Expand Up @@ -2007,7 +2007,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, IntPtr* __return_va
return 0;
}

unsafe internal static Nullable GetValue(IInspectable inspectable)
public static unsafe Nullable GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
IntPtr __retval = default;
Expand Down Expand Up @@ -2064,7 +2064,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, IntPtr* __return_va

public static Guid PIID = GuidGenerator.CreateIID(typeof(Nullable<T>));

unsafe internal static Nullable GetValue(IInspectable inspectable)
public static unsafe Nullable GetValue(IInspectable inspectable)
{
IntPtr nullablePtr = IntPtr.Zero;
IntPtr __retval = default;
Expand Down
14 changes: 6 additions & 8 deletions src/WinRT.Runtime/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ static class TypeExtensions

#if NET
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods |
DynamicallyAccessedMemberTypes.NonPublicMethods |
DynamicallyAccessedMemberTypes.PublicNestedTypes |
DynamicallyAccessedMemberTypes.PublicFields)]
#endif
Expand All @@ -30,7 +29,6 @@ public static Type FindHelperType(this Type type)
return HelperTypeCache.GetOrAdd(type,
#if NET
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods |
DynamicallyAccessedMemberTypes.NonPublicMethods |
DynamicallyAccessedMemberTypes.PublicNestedTypes |
DynamicallyAccessedMemberTypes.PublicFields)]
#endif
Expand Down Expand Up @@ -93,7 +91,6 @@ static Type FindHelperTypeFallback(Type type)

#if NET
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods |
DynamicallyAccessedMemberTypes.NonPublicMethods |
DynamicallyAccessedMemberTypes.PublicNestedTypes |
DynamicallyAccessedMemberTypes.PublicFields)]
#endif
Expand Down Expand Up @@ -152,25 +149,26 @@ internal static IntPtr GetAbiToProjectionVftblPtr(

public static Type GetAbiType(this Type type)
{
return type.GetHelperType().GetMethod("GetAbi", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).ReturnType;
return type.GetHelperType().GetMethod("GetAbi", BindingFlags.Public | BindingFlags.Static).ReturnType;
}

public static Type GetMarshalerType(this Type type)
{
return type.GetHelperType().GetMethod("CreateMarshaler", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).ReturnType;
return type.GetHelperType().GetMethod("CreateMarshaler", BindingFlags.Public | BindingFlags.Static).ReturnType;
}

internal static Type GetMarshaler2Type(this Type type)
{
var helperType = type.GetHelperType();
var createMarshaler = helperType.GetMethod("CreateMarshaler2", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static) ??
helperType.GetMethod("CreateMarshaler", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
var createMarshaler =
helperType.GetMethod("CreateMarshaler2", BindingFlags.Public | BindingFlags.Static) ??
helperType.GetMethod("CreateMarshaler", BindingFlags.Public | BindingFlags.Static);
return createMarshaler.ReturnType;
}

internal static Type GetMarshalerArrayType(this Type type)
{
return type.GetHelperType().GetMethod("CreateMarshalerArray", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)?.ReturnType;
return type.GetHelperType().GetMethod("CreateMarshalerArray", BindingFlags.Public | BindingFlags.Static)?.ReturnType;
}

public static bool IsDelegate(this Type type)
Expand Down
Loading