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

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

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

Definition at line 82 of file MemoryMarshal.cs.

82 : struct where TTo : struct
83 {
84 if (RuntimeHelpers.IsReferenceOrContainsReferences<TFrom>())
85 {
86 ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom));
87 }
88 if (RuntimeHelpers.IsReferenceOrContainsReferences<TTo>())
89 {
90 ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo));
91 }
92 uint num = (uint)Unsafe.SizeOf<TFrom>();
93 uint num2 = (uint)Unsafe.SizeOf<TTo>();
94 uint length = (uint)span.Length;
95 int length2;
96 if (num == num2)
97 {
98 length2 = (int)length;
99 }
100 else if (num == 1)
101 {
102 length2 = (int)(length / num2);
103 }
104 else
105 {
106 ulong num3 = (ulong)((long)length * (long)num) / (ulong)num2;
107 length2 = checked((int)num3);
108 }
109 return new Span<TTo>(ref Unsafe.As<TFrom, TTo>(ref span._pointer.Value), length2);
110 }

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