File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,11 @@ public static class NullableExtensions
35
35
public static ref T DangerousGetValueOrDefaultReference < T > ( this ref T ? value )
36
36
where T : struct
37
37
{
38
+ #if NET7_0_OR_GREATER
39
+ return ref Unsafe . AsRef ( in Nullable . GetValueRefOrDefaultRef ( in value ) ) ;
40
+ #else
38
41
return ref Unsafe . As < T ? , RawNullableData < T > > ( ref value ) . Value ;
42
+ #endif
39
43
}
40
44
41
45
/// <summary>
@@ -51,12 +55,17 @@ public static unsafe ref T DangerousGetValueOrNullReference<T>(ref this T? value
51
55
{
52
56
if ( value . HasValue )
53
57
{
58
+ #if NET7_0_OR_GREATER
59
+ return ref Unsafe . AsRef ( in Nullable . GetValueRefOrDefaultRef ( in value ) ) ;
60
+ #else
54
61
return ref Unsafe . As < T ? , RawNullableData < T > > ( ref value ) . Value ;
62
+ #endif
55
63
}
56
64
57
65
return ref Unsafe . NullRef < T > ( ) ;
58
66
}
59
67
68
+ #if ! NET7_0_OR_GREATER
60
69
/// <summary>
61
70
/// Mapping type that reflects the internal layout of the <see cref="Nullable{T}"/> type.
62
71
/// See https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/Nullable.cs.
@@ -70,6 +79,7 @@ private struct RawNullableData<T>
70
79
public T Value ;
71
80
#pragma warning restore CS0649
72
81
}
82
+ #endif
73
83
}
74
84
75
85
#endif
You can’t perform that action at this time.
0 commit comments