diff --git a/src/AppCoreNet.Diagnostics.Sources/Ensure.Arg.cs b/src/AppCoreNet.Diagnostics.Sources/Ensure.Arg.cs index 57dfa96..0d1f80d 100644 --- a/src/AppCoreNet.Diagnostics.Sources/Ensure.Arg.cs +++ b/src/AppCoreNet.Diagnostics.Sources/Ensure.Arg.cs @@ -349,8 +349,8 @@ public static void OfGenericType( /// The type argument is not of the expected type. [MethodImpl(MethodImplOptions.AggressiveInlining)] [StackTraceHidden] + [RequiresUnreferencedCode("Requires unreferenced code, use the overload with Type parameter.")] public static void OfGenericType( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] object? value, Type expectedType, [CallerArgumentExpression("value")] string? paramName = null) @@ -371,8 +371,8 @@ public static void OfGenericType( /// The type argument is not of the expected type. [MethodImpl(MethodImplOptions.AggressiveInlining)] [StackTraceHidden] + [RequiresUnreferencedCode("Requires unreferenced code, use the overload with Type parameter.")] public static void OfGenericType( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] object? value, [CallerArgumentExpression("value")] string? paramName = null) { diff --git a/test/AppCoreNet.Diagnostics.Tests/EnsureTests.Arg.cs b/test/AppCoreNet.Diagnostics.Tests/EnsureTests.Arg.cs index 9112fce..2e7ef43 100644 --- a/test/AppCoreNet.Diagnostics.Tests/EnsureTests.Arg.cs +++ b/test/AppCoreNet.Diagnostics.Tests/EnsureTests.Arg.cs @@ -4,6 +4,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using FluentAssertions; using Xunit; @@ -232,6 +233,7 @@ public void OfGenericTypeDoesNotThrowForRelatedTypes(Type expectedType) [InlineData(typeof(IEnumerable<>))] [InlineData(typeof(ExpectedArgBaseType))] [InlineData(typeof(ExpectedArgType))] + [RequiresUnreferencedCode("This test requires types to be preserved for reflection.")] public void OfGenericTypeDoesNotThrowForRelatedValue(Type expectedType) { object value = new ExpectedArgType(); @@ -245,6 +247,7 @@ public void OfGenericTypeDoesNotThrowForNullType() } [Fact] + [RequiresUnreferencedCode("This test requires types to be preserved for reflection.")] public void OfGenericTypeDoesNotThrowForNullValue() { Ensure.Arg.OfGenericType((object?)null, typeof(string)); @@ -261,6 +264,7 @@ public void OfGenericTypeThrowsForUnrelatedType() } [Fact] + [RequiresUnreferencedCode("This test requires types to be preserved for reflection.")] public void OfGenericTypeThrowsForUnrelatedValue() { var exception = Assert.Throws(