Idle curiosity: I just came across the following generated (ie via .tt) code.
Can anyone explain why it was written this way and not just a direct return. Perhaps it serves as a reinterpret or the like?
namespace System.Numerics
{
internal class ConstantHelper
{
[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
public static byte GetByteWithAllBitsSet() // Also GetInt16, GetInt32, etc
{
byte value = 0;
unsafe
{
unchecked
{
*((byte*)&value) = (byte)0xff;
}
}
return value;
}
Idle curiosity: I just came across the following generated (ie via
.tt
) code. Can anyone explain why it was written this way and not just a direct return. Perhaps it serves as a reinterpret or the like?https://github.com/dotnet/coreclr/blob/030a3ea9b8dbeae89c90d34441d4d9a1cf4a7de6/src/System.Private.CoreLib/shared/System/Numerics/ConstantHelper.cs