Skip to content

Commit 46fad62

Browse files
committed
Use extension method to check AOT compatibility
1 parent 7b89761 commit 46fad62

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/DotNext.AotTests/Runtime/BoxedValueTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public void BoxUnbox()
88
{
99
var obj = (BoxedValue<int>)42;
1010
// Assert.AreEqual(42.GetHashCode(), obj.GetHashCode());
11-
Assert.AreEqual(42, obj.Value);
11+
Assert.AreEqual(42, obj.GetReference());
1212
// Assert.AreEqual(42, (int)obj);
1313
// Assert.AreEqual(typeof(int), obj.GetType());
1414
}

src/DotNext/Runtime/BoxedValue.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace DotNext.Runtime;
2424
public class BoxedValue<T> // do not add any interfaces or base types
2525
where T : struct
2626
{
27-
private T value;
27+
internal T value;
2828

2929
static BoxedValue()
3030
{
@@ -119,4 +119,11 @@ private BoxedValue()
119119
/// <returns>Mutable reference to the boxed value.</returns>
120120
public static implicit operator ValueReference<T>(BoxedValue<T> boxedValue)
121121
=> new(boxedValue, ref boxedValue.value);
122+
}
123+
124+
public static class BoxedValue
125+
{
126+
public static ref T GetReference<T>(this BoxedValue<T> boxedValue)
127+
where T : struct
128+
=> ref boxedValue.value;
122129
}

0 commit comments

Comments
 (0)