-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from prozolic/pullreq
Change From Unsafe.As() To Unsafe.Bitcast()
- Loading branch information
Showing
2 changed files
with
50 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace CsToml.Utility; | ||
|
||
internal static class UnsafeHelper | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static TTo BitCast<TFrom, TTo>(TFrom source) | ||
{ | ||
#if NET9_0_OR_GREATER | ||
// the struct constraint is removed from .NET 9 , it is used as is. | ||
return Unsafe.BitCast<TFrom, TTo>(source); | ||
#else | ||
return Unsafe.ReadUnaligned<TTo>(ref Unsafe.As<TFrom, byte>(ref source)); | ||
#endif | ||
} | ||
} |