Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ValueToHexString() [1/2]

string System.Enum.ValueToHexString ( )
inlineprivate

Definition at line 89 of file Enum.cs.

90 {
91 ref byte rawData = ref this.GetRawData();
92 Span<byte> destination = stackalloc byte[8];
93 int length;
95 {
96 case CorElementType.ELEMENT_TYPE_I1:
97 case CorElementType.ELEMENT_TYPE_U1:
98 destination[0] = rawData;
99 length = 1;
100 break;
101 case CorElementType.ELEMENT_TYPE_BOOLEAN:
102 if (rawData == 0)
103 {
104 return "00";
105 }
106 return "01";
107 case CorElementType.ELEMENT_TYPE_CHAR:
108 case CorElementType.ELEMENT_TYPE_I2:
109 case CorElementType.ELEMENT_TYPE_U2:
110 BinaryPrimitives.WriteUInt16BigEndian(destination, Unsafe.As<byte, ushort>(ref rawData));
111 length = 2;
112 break;
113 case CorElementType.ELEMENT_TYPE_I4:
114 case CorElementType.ELEMENT_TYPE_U4:
115 BinaryPrimitives.WriteUInt32BigEndian(destination, Unsafe.As<byte, uint>(ref rawData));
116 length = 4;
117 break;
118 case CorElementType.ELEMENT_TYPE_I8:
119 case CorElementType.ELEMENT_TYPE_U8:
120 BinaryPrimitives.WriteUInt64BigEndian(destination, Unsafe.As<byte, ulong>(ref rawData));
121 length = 8;
122 break;
123 default:
124 throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType);
125 }
126 return HexConverter.ToString(destination.Slice(0, length));
127 }
static void WriteUInt32BigEndian(Span< byte > destination, uint value)
static void WriteUInt16BigEndian(Span< byte > destination, ushort value)
static void WriteUInt64BigEndian(Span< byte > destination, ulong value)
CorElementType InternalGetCorElementType()

References System.destination, System.Enum.InternalGetCorElementType(), System.SR.InvalidOperation_UnknownEnumType, System.length, System.HexConverter.ToString(), System.Buffers.Binary.BinaryPrimitives.WriteUInt16BigEndian(), System.Buffers.Binary.BinaryPrimitives.WriteUInt32BigEndian(), and System.Buffers.Binary.BinaryPrimitives.WriteUInt64BigEndian().

Referenced by System.Enum.Format(), and System.Enum.ToString().