Skip to content

Commit

Permalink
Use extension method to check AOT compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Jan 2, 2025
1 parent 7b89761 commit 46fad62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/DotNext.AotTests/Runtime/BoxedValueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public void BoxUnbox()
{
var obj = (BoxedValue<int>)42;
// Assert.AreEqual(42.GetHashCode(), obj.GetHashCode());
Assert.AreEqual(42, obj.Value);
Assert.AreEqual(42, obj.GetReference());
// Assert.AreEqual(42, (int)obj);
// Assert.AreEqual(typeof(int), obj.GetType());
}
Expand Down
9 changes: 8 additions & 1 deletion src/DotNext/Runtime/BoxedValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace DotNext.Runtime;
public class BoxedValue<T> // do not add any interfaces or base types
where T : struct
{
private T value;
internal T value;

static BoxedValue()
{
Expand Down Expand Up @@ -119,4 +119,11 @@ private BoxedValue()
/// <returns>Mutable reference to the boxed value.</returns>
public static implicit operator ValueReference<T>(BoxedValue<T> boxedValue)
=> new(boxedValue, ref boxedValue.value);
}

public static class BoxedValue
{
public static ref T GetReference<T>(this BoxedValue<T> boxedValue)
where T : struct
=> ref boxedValue.value;
}

0 comments on commit 46fad62

Please sign in to comment.