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

◆ Cast< TFrom, TTo >() [1/2]

static ReadOnlySpan< TTo > System.Runtime.InteropServices.MemoryMarshal.Cast< TFrom, TTo > ( ReadOnlySpan< TFrom > span)
inlinestatic
Type Constraints
TFrom :struct 
TTo :struct 

Definition at line 113 of file MemoryMarshal.cs.

113 : struct where TTo : struct
114 {
115 if (RuntimeHelpers.IsReferenceOrContainsReferences<TFrom>())
116 {
117 ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom));
118 }
119 if (RuntimeHelpers.IsReferenceOrContainsReferences<TTo>())
120 {
121 ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo));
122 }
123 uint num = (uint)Unsafe.SizeOf<TFrom>();
124 uint num2 = (uint)Unsafe.SizeOf<TTo>();
125 uint length = (uint)span.Length;
126 int length2;
127 if (num == num2)
128 {
129 length2 = (int)length;
130 }
131 else if (num == 1)
132 {
133 length2 = (int)(length / num2);
134 }
135 else
136 {
137 ulong num3 = (ulong)((long)length * (long)num) / (ulong)num2;
138 length2 = checked((int)num3);
139 }
140 return new ReadOnlySpan<TTo>(ref Unsafe.As<TFrom, TTo>(ref GetReference(span)), length2);
141 }

References System.length, System.length2, and System.ThrowHelper.ThrowInvalidTypeWithPointersNotSupported().