Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
81d1146
refactor(formatting): escape dots in strings to prevent namespace int…
thomhurst Oct 23, 2025
f1b749d
test(aot): add tests for AOT compatibility with enum arguments to pre…
thomhurst Oct 23, 2025
36a6f49
refactor(assertions): simplify assertion calls by removing unnecessar…
thomhurst Oct 23, 2025
fe7681d
refactor(matrix): streamline enum handling and remove unnecessary dyn…
thomhurst Oct 23, 2025
fa548ef
refactor(attributes): replace RequiresDynamicCode with RequiresUnrefe…
thomhurst Oct 23, 2025
735f0aa
test(aot): enhance AOT compatibility with property injection and dyna…
thomhurst Oct 23, 2025
a1d045b
refactor(tests): remove unused methods and improve AOT compatibility …
thomhurst Oct 23, 2025
3701435
chore(dependencies): update TUnit package version to 0.75.38-PullRequ…
thomhurst Oct 23, 2025
e581a0c
refactor(attributes): skip compiler-internal attributes during attrib…
thomhurst Oct 23, 2025
abb79d3
refactor(PropertyInjection): use non-nullable type names for improved…
thomhurst Oct 23, 2025
3b3f622
refactor(CastHelper): remove unnecessary suppress message for AOT com…
thomhurst Oct 23, 2025
4062403
refactor(CastHelper): simplify casting logic by removing unnecessary …
thomhurst Oct 23, 2025
099962b
refactor(CastHelper): enhance casting logic with AOT-safe conversions…
thomhurst Oct 23, 2025
a2c182b
refactor(CastHelper): optimize casting method by adding direct type c…
thomhurst Oct 23, 2025
2e31d58
refactor(CastHelper): improve AOT handling in TryReflectionConversion…
thomhurst Oct 24, 2025
c4052e9
feat: enhance AOT converter by scanning for conversion operators in s…
thomhurst Oct 24, 2025
9376b1e
feat: improve AOT converter by scanning all types in compilation for …
thomhurst Oct 24, 2025
f24825d
feat: add support for scanning closed generic types in method paramet…
thomhurst Oct 24, 2025
05063b5
feat: add AOT and single file publishing steps to CI pipeline
thomhurst Oct 24, 2025
0cdc612
feat: update TUnit package version references to use TUnitVersion var…
thomhurst Oct 24, 2025
917ea59
feat: add additional suppression message for trimming in reflection mode
thomhurst Oct 24, 2025
4a8ca00
feat: introduce IMemberMetadata interface and update related metadata…
thomhurst Oct 24, 2025
37e1e0a
fix: refine DynamicallyAccessedMembers attributes in Cast methods for…
thomhurst Oct 24, 2025
ecabc37
fix: update DynamicallyAccessedMembers attributes in Cast methods for…
thomhurst Oct 24, 2025
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
Prev Previous commit
Next Next commit
refactor(CastHelper): simplify casting logic by removing unnecessary …
…suppress messages and redundant code
  • Loading branch information
thomhurst committed Oct 24, 2025
commit 40624034a199e15be4ebbc259ccd47c2adbd45df
34 changes: 1 addition & 33 deletions TUnit.Core/Helpers/CastHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace TUnit.Core.Helpers;
[UnconditionalSuppressMessage("Trimming", "IL2072:Target parameter argument does not satisfy \'DynamicallyAccessedMembersAttribute\' in call to target method. The return value of the source method does not have matching annotations.")]
public static class CastHelper
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T? Cast<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] T>(object? value)
{
if (value is null)
Expand Down Expand Up @@ -179,9 +178,6 @@ public static class CastHelper
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[UnconditionalSuppressMessage("AOT", "IL3050:Calling members annotated with 'RequiresUnreferencedCodeAttribute' may break functionality when AOT compiling.",
Justification = "Array.CreateInstance is used for test data generation at discovery time, not in AOT-compiled test execution.")]
public static object? Cast([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Type type, object? value)
{
if (value is null)
Expand Down Expand Up @@ -212,35 +208,7 @@ public static class CastHelper
&& !value.GetType().IsArray // Don't unwrap arrays
&& !typeof(IEnumerable).IsAssignableFrom(type))
{
// Special handling for CustomAttributeTypedArgument collections in .NET Framework
var typeName = value.GetType().FullName;
if (typeName != null && typeName.Contains("CustomAttributeTypedArgument"))
{
// For ReadOnlyCollection<CustomAttributeTypedArgument>, we need to extract the actual values
var firstItem = enumerable.Cast<object>().FirstOrDefault();
if (firstItem != null)
{
ThrowOnAot(value, underlyingType);
// Use reflection to get the Value property
var valueProperty = GetValuePropertySafe(firstItem.GetType());
if (valueProperty != null)
{
value = valueProperty.GetValue(firstItem);
}
else
{
value = firstItem;
}
}
else
{
value = null;
}
}
else
{
value = enumerable.Cast<object>().ElementAtOrDefault(0);
}
value = enumerable.Cast<object>().ElementAtOrDefault(0);
}

if (underlyingType.IsEnum)
Expand Down