fixes and adjustments
.NET Test / .NET tests (push) Successful in 2m53s

This commit is contained in:
2026-07-16 19:00:05 +04:00
parent 0e7986996f
commit 04c682d6fd
4 changed files with 177 additions and 28 deletions
+19
View File
@@ -4,9 +4,22 @@ namespace Just.Railway;
internal static class ReflectionHelper
{
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
public static R ObjectCast<R>(object value) where R: class => (R)value;
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsEqual<T>(T? left, T? right) => TypeReflectionCache<T>.IsEqualFunc(left, right);
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
/// <summary>
/// Test for potential nullability
/// </summary>
/// <returns>true if T is reference type or Nullable value type.</returns>
public static bool IsNullable<T>() => TypeReflectionCache<T>.IsNullable;
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNullableStruct<T>() => TypeReflectionCache<T>.IsNullableStruct;
private static class TypeReflectionCache<T>
{
public static readonly Func<T?, T?, bool> IsEqualFunc;
@@ -30,8 +43,14 @@ internal static class ReflectionHelper
{
IsEqualFunc = static (left, right) => left is null ? right is null : left.Equals(right);
}
IsNullableStruct = isNullableStruct;
IsNullable = isNullableStruct || !type.IsValueType;
}
public static bool IsNullable { get; }
public static bool IsNullableStruct { get; }
#pragma warning disable CS8604 // Possible null reference argument.
[Pure] public static bool IsEqual<R>(R? left, R? right) where R : notnull, IEquatable<R>, T => left is null ? right is null : left.Equals(right);
[Pure] public static bool IsEqualNullable<R>(R? left, R? right) where R : struct, IEquatable<R> => left is null ? right is null : right is not null && left.Value.Equals(right.Value);