Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/ExcelReader.Core/Parser/SyncRowEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,14 @@ private protected SyncRowEnumerator(TRows rows)

object? IEnumerator.Current => typeof(T).IsByRefLike ? throw new NotSupportedException() : Box(Project());

private sealed class RawData
{
public byte Data;
}

// T allows ref struct, so the language refuses (object)value; the byref-like case is excluded by the caller.
private static object? Box(T value)
{
if (!typeof(T).IsValueType)
{
return Unsafe.As<T, object>(ref value);
}
object box = RuntimeHelpers.GetUninitializedObject(typeof(T));
Unsafe.As<byte, T>(ref Unsafe.As<RawData>(box).Data) = value;
return box;
return RuntimeHelpers.Box(ref Unsafe.As<T, byte>(ref value), typeof(T).TypeHandle);
}

/// <inheritdoc/>
Expand Down
1 change: 1 addition & 0 deletions src/ExcelReader.Core/Reader/SheetDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public Type GetFieldType(int i)
return TypeOf(CurrentCell(i));
}

[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties)]
private static Type TypeOf(Cell cell)
{
return cell.Type switch
Expand Down
Loading