Skip to content

Commit 7b89761

Browse files
committed
Revert "Use IL to achieve AOT visibility"
This reverts commit 005a628.
1 parent 005a628 commit 7b89761

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/DotNext/Runtime/BoxedValue.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using System.Diagnostics;
22
using System.Diagnostics.CodeAnalysis;
33
using System.Runtime.CompilerServices;
4-
using static InlineIL.IL;
5-
using static InlineIL.IL.Emit;
6-
using static InlineIL.MethodRef;
7-
using static InlineIL.TypeRef;
84

95
namespace DotNext.Runtime;
106

@@ -29,6 +25,13 @@ namespace DotNext.Runtime;
2925
where T : struct
3026
{
3127
private T value;
28+
29+
static BoxedValue()
30+
{
31+
// AOT: instantiate the class to make instance members visible to AOT
32+
var boxed = new BoxedValue<T>();
33+
GC.KeepAlive(boxed);
34+
}
3235

3336
[ExcludeFromCodeCoverage]
3437
private BoxedValue()
@@ -63,22 +66,15 @@ private BoxedValue()
6366
/// </summary>
6467
/// <param name="value">The value to be boxed.</param>
6568
/// <returns>A boxed representation of the value.</returns>
66-
public static BoxedValue<T> Box(T value)
67-
{
68-
Push(value);
69-
Box<T>();
70-
Dup();
71-
Call(Constructor(Type<BoxedValue<T>>()));
72-
return Return<BoxedValue<T>>();
73-
}
69+
public static BoxedValue<T> Box(T value) => Unsafe.As<BoxedValue<T>>(value);
7470

7571
/// <summary>
7672
/// Boxes nullable value type to an object.
7773
/// </summary>
7874
/// <param name="value">The value to be boxed.</param>
7975
/// <returns>A boxed representation of the value.</returns>
8076
[return: NotNullIfNotNull(nameof(value))]
81-
public static BoxedValue<T>? TryBox(in T? value) => value.HasValue ? Box(value.GetValueOrDefault()) : null;
77+
public static BoxedValue<T>? TryBox(in T? value) => Unsafe.As<BoxedValue<T>?>(value);
8278

8379
/// <summary>
8480
/// Unboxes the value.

0 commit comments

Comments
 (0)