Skip to content

Commit

Permalink
Centralize [RDC] messages in TrimmingAttributeMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Jan 23, 2024
1 parent 9132288 commit 1859080
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/ComWrappersSupport.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private static Func<IInspectable, object> CreateFactoryForImplementationType(str
return (IInspectable obj) => constructor.Invoke(new[] { obj.ObjRef });

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
static Type GetGenericImplType(Type implementationType)
Expand Down
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/Marshalers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ private static IObjectReference CreateMarshalerCore(T value)
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static Func<T, IObjectReference> BindCreateMarshaler()
{
Expand Down
10 changes: 5 additions & 5 deletions src/WinRT.Runtime/Projections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public static bool TryGetCompatibleWindowsRuntimeTypeForVariantType(Type type, o
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static HashSet<Type> GetCompatibleTypes(Type type, Stack<Type> typeStack)
{
Expand Down Expand Up @@ -407,7 +407,7 @@ private static HashSet<Type> GetCompatibleTypes(Type type, Stack<Type> typeStack
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
internal static IEnumerable<Type> GetAllPossibleTypeCombinations(IEnumerable<IEnumerable<Type>> compatibleTypesPerGeneric, Type definition)
{
Expand All @@ -425,7 +425,7 @@ internal static IEnumerable<Type> GetAllPossibleTypeCombinations(IEnumerable<IEn
return accum;

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
#if NET
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Expand Down Expand Up @@ -453,7 +453,7 @@ void GetAllPossibleTypeCombinationsCore(List<Type> accum, Stack<Type> stack, IEn
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
internal static bool TryGetCompatibleWindowsRuntimeTypesForVariantType(Type type, Stack<Type> typeStack, out IEnumerable<Type> compatibleTypes)
{
Expand Down Expand Up @@ -597,7 +597,7 @@ internal static bool TryGetMarshalerTypeForProjectedRuntimeClass<T>(IObjectRefer

#if NET
#if NET8_0_OR_GREATER
[RequiresDynamicCode("Native code for the delegate type migth not be available.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
internal static Type GetAbiDelegateType(params Type[] typeArgs) => Expression.GetDelegateType(typeArgs);
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class GenericDelegateHelper
internal static ConditionalWeakTable<IObjectReference, object> DelegateTable = new();

#if NET8_0_OR_GREATER
[RequiresDynamicCode("Marshalling code might not be available at runtime in AOT environments.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
internal unsafe static Delegate CreateDelegate(IntPtr ptr, ref Delegate delegateRef, Type delegateType, int offset)
{
Expand Down
32 changes: 16 additions & 16 deletions src/WinRT.Runtime/Projections/IDictionary.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ public unsafe static bool InitRcwHelper(
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private unsafe static bool InitRcwHelperFallback()
{
Expand All @@ -735,7 +735,7 @@ private unsafe static bool InitRcwHelperFallback()
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static unsafe V LookupDynamic(IObjectReference obj, K key)
{
Expand All @@ -758,7 +758,7 @@ private static unsafe V LookupDynamic(IObjectReference obj, K key)
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static unsafe bool HasKeyDynamic(IObjectReference obj, K key)
{
Expand All @@ -780,7 +780,7 @@ private static unsafe bool HasKeyDynamic(IObjectReference obj, K key)
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static unsafe bool InsertDynamic(IObjectReference obj, K key, V value)
{
Expand All @@ -806,7 +806,7 @@ private static unsafe bool InsertDynamic(IObjectReference obj, K key, V value)
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static unsafe void RemoveDynamic(IObjectReference obj, K key)
{
Expand Down Expand Up @@ -861,7 +861,7 @@ public static unsafe bool InitCcw(
private static global::System.Delegate[] DelegateCache;

#if NET8_0_OR_GREATER
[RequiresDynamicCode("Marshalling code might not be available in AOT environments.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
internal static unsafe void InitFallbackCCWVtable()
{
Expand Down Expand Up @@ -1021,13 +1021,13 @@ private static unsafe int Do_Abi_get_Size_1(IntPtr thisPtr, uint* __return_value
private static global::System.Type Lookup_0_Type
{
#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
get => _lookup_0_type ?? MakeLookupType();
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static global::System.Type MakeLookupType()
{
Expand All @@ -1039,13 +1039,13 @@ private static unsafe int Do_Abi_get_Size_1(IntPtr thisPtr, uint* __return_value
private static global::System.Type HasKey_2_Type
{
#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
get => _hasKey_2_type ?? MakeHasKeyType();
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static global::System.Type MakeHasKeyType()
{
Expand All @@ -1057,13 +1057,13 @@ private static unsafe int Do_Abi_get_Size_1(IntPtr thisPtr, uint* __return_value
private static global::System.Type Insert_4_Type
{
#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
get => _insert_4_type ?? MakeInsertType();
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static global::System.Type MakeInsertType()
{
Expand All @@ -1075,13 +1075,13 @@ private static unsafe int Do_Abi_get_Size_1(IntPtr thisPtr, uint* __return_value
private static global::System.Type Remove_5_Type
{
#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
get => _remove_5_type ?? MakeRemoveType();
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static global::System.Type MakeRemoveType()
{
Expand All @@ -1090,7 +1090,7 @@ private static unsafe int Do_Abi_get_Size_1(IntPtr thisPtr, uint* __return_value
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private sealed class DelegateHelper
{
Expand Down Expand Up @@ -1226,7 +1226,7 @@ static IDictionary()
#pragma warning restore IL3050

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitFallbackCCWVTableIfNeeded()
Expand Down
6 changes: 3 additions & 3 deletions src/WinRT.Runtime/Projections/IEnumerable.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ static IEnumerable()
#pragma warning restore IL3050

#if NET8_0_OR_GREATER
[RequiresDynamicCode("Marshalling code might not be available in AOT environments.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitFallbackCCWVTableIfNeeded()
Expand Down Expand Up @@ -659,7 +659,7 @@ public static unsafe bool InitCcw(
private static global::System.Delegate[] DelegateCache;

#if NET8_0_OR_GREATER
[RequiresDynamicCode("Marshalling code might not be available in AOT environments.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
internal static unsafe void InitFallbackCCWVtable()
{
Expand Down Expand Up @@ -1058,7 +1058,7 @@ static IEnumerator()
#pragma warning restore IL3050

#if NET8_0_OR_GREATER
[RequiresDynamicCode("Marshalling code might not be available in AOT environments.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitFallbackCCWVTableIfNeeded()
Expand Down
28 changes: 14 additions & 14 deletions src/WinRT.Runtime/Projections/IList.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public unsafe static bool InitRcwHelper(
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("Marshalling code might not be available in AOT environments.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private unsafe static bool InitRcwHelperFallback()
{
Expand Down Expand Up @@ -503,7 +503,7 @@ private static unsafe T GetAtDynamic(IObjectReference obj, uint index)
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("Marshalling code might not be available in AOT environments.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static unsafe bool IndexOfDynamic(IObjectReference obj, T value, out uint index)
{
Expand All @@ -527,7 +527,7 @@ private static unsafe bool IndexOfDynamic(IObjectReference obj, T value, out uin
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("Marshalling code might not be available in AOT environments.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static unsafe void SetAtDynamic(IObjectReference obj, uint index, T value)
{
Expand All @@ -547,7 +547,7 @@ private static unsafe void SetAtDynamic(IObjectReference obj, uint index, T valu
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("Marshalling code might not be available in AOT environments.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static unsafe void InsertAtDynamic(IObjectReference obj, uint index, T value)
{
Expand All @@ -567,7 +567,7 @@ private static unsafe void InsertAtDynamic(IObjectReference obj, uint index, T v
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("Marshalling code might not be available in AOT environments.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static unsafe void AppendDynamic(IObjectReference obj, T value)
{
Expand Down Expand Up @@ -632,7 +632,7 @@ public static unsafe bool InitCcw(
private static global::System.Delegate[] DelegateCache;

#if NET8_0_OR_GREATER
[RequiresDynamicCode("Marshalling code might not be available in AOT environments.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
internal static unsafe void InitFallbackCCWVtable()
{
Expand Down Expand Up @@ -875,14 +875,14 @@ private static unsafe int Do_Abi_get_Size_1(IntPtr thisPtr, uint* __return_value
private static Type IndexOf_3_Type
{
#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
get => _indexOf_3_type ?? MakeIndexOfType();
}


#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static Type MakeIndexOfType()
{
Expand All @@ -894,14 +894,14 @@ private static Type MakeIndexOfType()
private static Type SetAtInsertAt_Type
{
#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
get => _setAtInsertAt_Type ?? MakeSetAtInsertAtType();
}


#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static Type MakeSetAtInsertAtType()
{
Expand All @@ -913,14 +913,14 @@ private static Type MakeSetAtInsertAtType()
private static Type Append_7_Type
{
#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
get => _append_7_Type ?? MakeAppendType();
}


#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private static Type MakeAppendType()
{
Expand All @@ -929,7 +929,7 @@ private static Type MakeAppendType()
}

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
private sealed class DelegateHelper
{
Expand Down Expand Up @@ -1345,7 +1345,7 @@ static IList()
#pragma warning restore IL3050

#if NET8_0_OR_GREATER
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresDynamicCode(TrimmingAttributeMessages.MarshallingOrGenericInstantiationsRequiresDynamicCode)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitFallbackCCWVTableIfNeeded()
Expand Down
Loading

0 comments on commit 1859080

Please sign in to comment.