Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TypedReference.cs
Go to the documentation of this file.
5
6namespace System;
7
8[CLSCompliant(false)]
9[NonVersionable]
10public ref struct TypedReference
11{
12 private readonly ByReference<byte> _value;
13
14 private readonly IntPtr _type;
15
16 internal bool IsNull
17 {
18 get
19 {
20 if (Unsafe.IsNullRef(ref _value.Value))
21 {
22 return _type == IntPtr.Zero;
23 }
24 return false;
25 }
26 }
27
28 public unsafe static TypedReference MakeTypedReference(object target, FieldInfo[] flds)
29 {
30 if (target == null)
31 {
32 throw new ArgumentNullException("target");
33 }
34 if (flds == null)
35 {
36 throw new ArgumentNullException("flds");
37 }
38 if (flds.Length == 0)
39 {
40 throw new ArgumentException(SR.Arg_ArrayZeroError, "flds");
41 }
42 IntPtr[] array = new IntPtr[flds.Length];
43 RuntimeType runtimeType = (RuntimeType)target.GetType();
44 for (int i = 0; i < flds.Length; i++)
45 {
46 RuntimeFieldInfo runtimeFieldInfo = flds[i] as RuntimeFieldInfo;
47 if (runtimeFieldInfo == null)
48 {
50 }
51 if (runtimeFieldInfo.IsStatic)
52 {
54 }
55 if (runtimeType != runtimeFieldInfo.GetDeclaringTypeInternal() && !runtimeType.IsSubclassOf(runtimeFieldInfo.GetDeclaringTypeInternal()))
56 {
58 }
59 RuntimeType runtimeType2 = (RuntimeType)runtimeFieldInfo.FieldType;
60 if (runtimeType2.IsPrimitive)
61 {
62 throw new ArgumentException(SR.Format(SR.Arg_TypeRefPrimitve, runtimeFieldInfo.Name));
63 }
64 if (i < flds.Length - 1 && !runtimeType2.IsValueType)
65 {
67 }
68 array[i] = runtimeFieldInfo.FieldHandle.Value;
69 runtimeType = runtimeType2;
70 }
71 TypedReference result = default(TypedReference);
72 InternalMakeTypedReference(&result, target, array, runtimeType);
73 return result;
74 }
75
76 [MethodImpl(MethodImplOptions.InternalCall)]
77 private unsafe static extern void InternalMakeTypedReference(void* result, object target, IntPtr[] flds, RuntimeType lastFieldType);
78
79 public override int GetHashCode()
80 {
81 if (_type == IntPtr.Zero)
82 {
83 return 0;
84 }
85 return __reftype(this).GetHashCode();
86 }
87
88 public override bool Equals(object? o)
89 {
91 }
92
93 public unsafe static object ToObject(TypedReference value)
94 {
95 return InternalToObject(&value);
96 }
97
98 [MethodImpl(MethodImplOptions.InternalCall)]
99 internal unsafe static extern object InternalToObject(void* value);
100
102 {
103 return __reftype(value);
104 }
105
107 {
108 return __reftype(value).TypeHandle;
109 }
110
111 public static void SetTypedReference(TypedReference target, object? value)
112 {
113 throw new NotSupportedException();
114 }
115}
RuntimeFieldHandle FieldHandle
Definition FieldInfo.cs:45
override bool IsSubclassOf(Type type)
static string Argument_TypedReferenceInvalidField
Definition SR.cs:892
static string NotSupported_NYI
Definition SR.cs:1698
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Arg_ArrayZeroError
Definition SR.cs:78
static string MissingMemberNestErr
Definition SR.cs:1632
static string Arg_TypeRefPrimitve
Definition SR.cs:436
static string Argument_MustBeRuntimeFieldInfo
Definition SR.cs:776
static string MissingMemberTypeRef
Definition SR.cs:1634
Definition SR.cs:7
bool IsValueType
Definition Type.cs:234
bool IsPrimitive
Definition Type.cs:231
static readonly IntPtr Zero
Definition IntPtr.cs:18
static unsafe void InternalMakeTypedReference(void *result, object target, IntPtr[] flds, RuntimeType lastFieldType)
static unsafe object ToObject(TypedReference value)
static RuntimeTypeHandle TargetTypeToken(TypedReference value)
readonly IntPtr _type
readonly ByReference< byte > _value
override bool Equals(object? o)
static unsafe object InternalToObject(void *value)
static Type GetTargetType(TypedReference value)
static unsafe TypedReference MakeTypedReference(object target, FieldInfo[] flds)
override int GetHashCode()
static void SetTypedReference(TypedReference target, object? value)