Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MetadataImport.cs
Go to the documentation of this file.
3
4namespace System.Reflection;
5
6internal readonly struct MetadataImport
7{
8 private readonly IntPtr m_metadataImport2;
9
10 private readonly object m_keepalive;
11
12 internal static readonly MetadataImport EmptyImport = new MetadataImport((IntPtr)0, null);
13
14 public override int GetHashCode()
15 {
17 }
18
19 public override bool Equals(object obj)
20 {
21 if (!(obj is MetadataImport))
22 {
23 return false;
24 }
25 return Equals((MetadataImport)obj);
26 }
27
28 private bool Equals(MetadataImport import)
29 {
30 return import.m_metadataImport2 == m_metadataImport2;
31 }
32
33 [MethodImpl(MethodImplOptions.InternalCall)]
34 private static extern void _GetMarshalAs(IntPtr pNativeType, int cNativeType, out int unmanagedType, out int safeArraySubType, out string safeArrayUserDefinedSubType, out int arraySubType, out int sizeParamIndex, out int sizeConst, out string marshalType, out string marshalCookie, out int iidParamIndex);
35
36 internal static void GetMarshalAs(ConstArray nativeType, out UnmanagedType unmanagedType, out VarEnum safeArraySubType, out string safeArrayUserDefinedSubType, out UnmanagedType arraySubType, out int sizeParamIndex, out int sizeConst, out string marshalType, out string marshalCookie, out int iidParamIndex)
37 {
38 _GetMarshalAs(nativeType.Signature, nativeType.Length, out var unmanagedType2, out var safeArraySubType2, out safeArrayUserDefinedSubType, out var arraySubType2, out sizeParamIndex, out sizeConst, out marshalType, out marshalCookie, out iidParamIndex);
39 unmanagedType = (UnmanagedType)unmanagedType2;
40 safeArraySubType = (VarEnum)safeArraySubType2;
41 arraySubType = (UnmanagedType)arraySubType2;
42 }
43
44 internal static void ThrowError(int hResult)
45 {
46 throw new MetadataException(hResult);
47 }
48
49 internal MetadataImport(IntPtr metadataImport2, object keepalive)
50 {
51 m_metadataImport2 = metadataImport2;
52 m_keepalive = keepalive;
53 }
54
55 [MethodImpl(MethodImplOptions.InternalCall)]
56 private static extern void _Enum(IntPtr scope, int type, int parent, out MetadataEnumResult result);
57
58 public void Enum(MetadataTokenType type, int parent, out MetadataEnumResult result)
59 {
60 _Enum(m_metadataImport2, (int)type, parent, out result);
61 }
62
63 public void EnumNestedTypes(int mdTypeDef, out MetadataEnumResult result)
64 {
65 Enum(MetadataTokenType.TypeDef, mdTypeDef, out result);
66 }
67
68 public void EnumCustomAttributes(int mdToken, out MetadataEnumResult result)
69 {
70 Enum(MetadataTokenType.CustomAttribute, mdToken, out result);
71 }
72
73 public void EnumParams(int mdMethodDef, out MetadataEnumResult result)
74 {
75 Enum(MetadataTokenType.ParamDef, mdMethodDef, out result);
76 }
77
78 public void EnumFields(int mdTypeDef, out MetadataEnumResult result)
79 {
80 Enum(MetadataTokenType.FieldDef, mdTypeDef, out result);
81 }
82
83 public void EnumProperties(int mdTypeDef, out MetadataEnumResult result)
84 {
85 Enum(MetadataTokenType.Property, mdTypeDef, out result);
86 }
87
88 public void EnumEvents(int mdTypeDef, out MetadataEnumResult result)
89 {
90 Enum(MetadataTokenType.Event, mdTypeDef, out result);
91 }
92
93 [MethodImpl(MethodImplOptions.InternalCall)]
94 private static extern string _GetDefaultValue(IntPtr scope, int mdToken, out long value, out int length, out int corElementType);
95
96 public string GetDefaultValue(int mdToken, out long value, out int length, out CorElementType corElementType)
97 {
98 int corElementType2;
99 string result = _GetDefaultValue(m_metadataImport2, mdToken, out value, out length, out corElementType2);
100 corElementType = (CorElementType)corElementType2;
101 return result;
102 }
103
104 [MethodImpl(MethodImplOptions.InternalCall)]
105 private unsafe static extern void _GetUserString(IntPtr scope, int mdToken, void** name, out int length);
106
107 public unsafe string GetUserString(int mdToken)
108 {
109 System.Runtime.CompilerServices.Unsafe.SkipInit(out void* ptr);
110 _GetUserString(m_metadataImport2, mdToken, &ptr, out var length);
111 if (ptr == null)
112 {
113 return null;
114 }
115 return new string((char*)ptr, 0, length);
116 }
117
118 [MethodImpl(MethodImplOptions.InternalCall)]
119 private unsafe static extern void _GetName(IntPtr scope, int mdToken, void** name);
120
121 public unsafe MdUtf8String GetName(int mdToken)
122 {
123 System.Runtime.CompilerServices.Unsafe.SkipInit(out void* pStringHeap);
124 _GetName(m_metadataImport2, mdToken, &pStringHeap);
125 return new MdUtf8String(pStringHeap);
126 }
127
128 [MethodImpl(MethodImplOptions.InternalCall)]
129 private unsafe static extern void _GetNamespace(IntPtr scope, int mdToken, void** namesp);
130
131 public unsafe MdUtf8String GetNamespace(int mdToken)
132 {
133 System.Runtime.CompilerServices.Unsafe.SkipInit(out void* pStringHeap);
134 _GetNamespace(m_metadataImport2, mdToken, &pStringHeap);
135 return new MdUtf8String(pStringHeap);
136 }
137
138 [MethodImpl(MethodImplOptions.InternalCall)]
139 private unsafe static extern void _GetEventProps(IntPtr scope, int mdToken, void** name, out int eventAttributes);
140
141 public unsafe void GetEventProps(int mdToken, out void* name, out EventAttributes eventAttributes)
142 {
143 System.Runtime.CompilerServices.Unsafe.SkipInit(out void* ptr);
144 _GetEventProps(m_metadataImport2, mdToken, &ptr, out var eventAttributes2);
145 name = ptr;
146 eventAttributes = (EventAttributes)eventAttributes2;
147 }
148
149 [MethodImpl(MethodImplOptions.InternalCall)]
150 private static extern void _GetFieldDefProps(IntPtr scope, int mdToken, out int fieldAttributes);
151
152 public void GetFieldDefProps(int mdToken, out FieldAttributes fieldAttributes)
153 {
154 _GetFieldDefProps(m_metadataImport2, mdToken, out var fieldAttributes2);
155 fieldAttributes = (FieldAttributes)fieldAttributes2;
156 }
157
158 [MethodImpl(MethodImplOptions.InternalCall)]
159 private unsafe static extern void _GetPropertyProps(IntPtr scope, int mdToken, void** name, out int propertyAttributes, out ConstArray signature);
160
161 public unsafe void GetPropertyProps(int mdToken, out void* name, out PropertyAttributes propertyAttributes, out ConstArray signature)
162 {
163 System.Runtime.CompilerServices.Unsafe.SkipInit(out void* ptr);
164 _GetPropertyProps(m_metadataImport2, mdToken, &ptr, out var propertyAttributes2, out signature);
165 name = ptr;
166 propertyAttributes = (PropertyAttributes)propertyAttributes2;
167 }
168
169 [MethodImpl(MethodImplOptions.InternalCall)]
170 private static extern void _GetParentToken(IntPtr scope, int mdToken, out int tkParent);
171
172 public int GetParentToken(int tkToken)
173 {
174 _GetParentToken(m_metadataImport2, tkToken, out var tkParent);
175 return tkParent;
176 }
177
178 [MethodImpl(MethodImplOptions.InternalCall)]
179 private static extern void _GetParamDefProps(IntPtr scope, int parameterToken, out int sequence, out int attributes);
180
181 public void GetParamDefProps(int parameterToken, out int sequence, out ParameterAttributes attributes)
182 {
183 _GetParamDefProps(m_metadataImport2, parameterToken, out sequence, out var attributes2);
184 attributes = (ParameterAttributes)attributes2;
185 }
186
187 [MethodImpl(MethodImplOptions.InternalCall)]
188 private static extern void _GetGenericParamProps(IntPtr scope, int genericParameter, out int flags);
189
190 public void GetGenericParamProps(int genericParameter, out GenericParameterAttributes attributes)
191 {
192 _GetGenericParamProps(m_metadataImport2, genericParameter, out var flags);
193 attributes = (GenericParameterAttributes)flags;
194 }
195
196 [MethodImpl(MethodImplOptions.InternalCall)]
197 private static extern void _GetScopeProps(IntPtr scope, out Guid mvid);
198
199 public void GetScopeProps(out Guid mvid)
200 {
202 }
203
205 {
206 if (token.IsMemberRef)
207 {
208 return GetMemberRefProps(token);
209 }
210 return GetSigOfMethodDef(token);
211 }
212
213 [MethodImpl(MethodImplOptions.InternalCall)]
214 private static extern void _GetSigOfMethodDef(IntPtr scope, int methodToken, ref ConstArray signature);
215
216 public ConstArray GetSigOfMethodDef(int methodToken)
217 {
218 ConstArray signature = default(ConstArray);
219 _GetSigOfMethodDef(m_metadataImport2, methodToken, ref signature);
220 return signature;
221 }
222
223 [MethodImpl(MethodImplOptions.InternalCall)]
224 private static extern void _GetSignatureFromToken(IntPtr scope, int methodToken, ref ConstArray signature);
225
227 {
228 ConstArray signature = default(ConstArray);
229 _GetSignatureFromToken(m_metadataImport2, token, ref signature);
230 return signature;
231 }
232
233 [MethodImpl(MethodImplOptions.InternalCall)]
234 private static extern void _GetMemberRefProps(IntPtr scope, int memberTokenRef, out ConstArray signature);
235
236 public ConstArray GetMemberRefProps(int memberTokenRef)
237 {
238 _GetMemberRefProps(m_metadataImport2, memberTokenRef, out var signature);
239 return signature;
240 }
241
242 [MethodImpl(MethodImplOptions.InternalCall)]
243 private static extern void _GetCustomAttributeProps(IntPtr scope, int customAttributeToken, out int constructorToken, out ConstArray signature);
244
245 public void GetCustomAttributeProps(int customAttributeToken, out int constructorToken, out ConstArray signature)
246 {
247 _GetCustomAttributeProps(m_metadataImport2, customAttributeToken, out constructorToken, out signature);
248 }
249
250 [MethodImpl(MethodImplOptions.InternalCall)]
251 private static extern void _GetClassLayout(IntPtr scope, int typeTokenDef, out int packSize, out int classSize);
252
253 public void GetClassLayout(int typeTokenDef, out int packSize, out int classSize)
254 {
255 _GetClassLayout(m_metadataImport2, typeTokenDef, out packSize, out classSize);
256 }
257
258 [MethodImpl(MethodImplOptions.InternalCall)]
259 private static extern bool _GetFieldOffset(IntPtr scope, int typeTokenDef, int fieldTokenDef, out int offset);
260
261 public bool GetFieldOffset(int typeTokenDef, int fieldTokenDef, out int offset)
262 {
263 return _GetFieldOffset(m_metadataImport2, typeTokenDef, fieldTokenDef, out offset);
264 }
265
266 [MethodImpl(MethodImplOptions.InternalCall)]
267 private static extern void _GetSigOfFieldDef(IntPtr scope, int fieldToken, ref ConstArray fieldMarshal);
268
269 public ConstArray GetSigOfFieldDef(int fieldToken)
270 {
271 ConstArray fieldMarshal = default(ConstArray);
272 _GetSigOfFieldDef(m_metadataImport2, fieldToken, ref fieldMarshal);
273 return fieldMarshal;
274 }
275
276 [MethodImpl(MethodImplOptions.InternalCall)]
277 private static extern void _GetFieldMarshal(IntPtr scope, int fieldToken, ref ConstArray fieldMarshal);
278
279 public ConstArray GetFieldMarshal(int fieldToken)
280 {
281 ConstArray fieldMarshal = default(ConstArray);
282 _GetFieldMarshal(m_metadataImport2, fieldToken, ref fieldMarshal);
283 return fieldMarshal;
284 }
285
286 [MethodImpl(MethodImplOptions.InternalCall)]
287 private unsafe static extern void _GetPInvokeMap(IntPtr scope, int token, out int attributes, void** importName, void** importDll);
288
289 public unsafe void GetPInvokeMap(int token, out PInvokeAttributes attributes, out string importName, out string importDll)
290 {
291 System.Runtime.CompilerServices.Unsafe.SkipInit(out void* pStringHeap);
292 System.Runtime.CompilerServices.Unsafe.SkipInit(out void* pStringHeap2);
293 _GetPInvokeMap(m_metadataImport2, token, out var attributes2, &pStringHeap, &pStringHeap2);
294 importName = new MdUtf8String(pStringHeap).ToString();
295 importDll = new MdUtf8String(pStringHeap2).ToString();
296 attributes = (PInvokeAttributes)attributes2;
297 }
298
299 [MethodImpl(MethodImplOptions.InternalCall)]
300 private static extern bool _IsValidToken(IntPtr scope, int token);
301
302 public bool IsValidToken(int token)
303 {
304 return _IsValidToken(m_metadataImport2, token);
305 }
306}
static int GetHashCodeOfPtr(IntPtr ptr)
unsafe override string ToString()
static bool _GetFieldOffset(IntPtr scope, int typeTokenDef, int fieldTokenDef, out int offset)
bool GetFieldOffset(int typeTokenDef, int fieldTokenDef, out int offset)
unsafe void GetEventProps(int mdToken, out void *name, out EventAttributes eventAttributes)
static void _GetMarshalAs(IntPtr pNativeType, int cNativeType, out int unmanagedType, out int safeArraySubType, out string safeArrayUserDefinedSubType, out int arraySubType, out int sizeParamIndex, out int sizeConst, out string marshalType, out string marshalCookie, out int iidParamIndex)
static void ThrowError(int hResult)
static unsafe void _GetEventProps(IntPtr scope, int mdToken, void **name, out int eventAttributes)
bool Equals(MetadataImport import)
static void _Enum(IntPtr scope, int type, int parent, out MetadataEnumResult result)
static void _GetCustomAttributeProps(IntPtr scope, int customAttributeToken, out int constructorToken, out ConstArray signature)
MetadataImport(IntPtr metadataImport2, object keepalive)
void GetFieldDefProps(int mdToken, out FieldAttributes fieldAttributes)
string GetDefaultValue(int mdToken, out long value, out int length, out CorElementType corElementType)
static void _GetParamDefProps(IntPtr scope, int parameterToken, out int sequence, out int attributes)
static void _GetClassLayout(IntPtr scope, int typeTokenDef, out int packSize, out int classSize)
static unsafe void _GetUserString(IntPtr scope, int mdToken, void **name, out int length)
static unsafe void _GetPInvokeMap(IntPtr scope, int token, out int attributes, void **importName, void **importDll)
static void GetMarshalAs(ConstArray nativeType, out UnmanagedType unmanagedType, out VarEnum safeArraySubType, out string safeArrayUserDefinedSubType, out UnmanagedType arraySubType, out int sizeParamIndex, out int sizeConst, out string marshalType, out string marshalCookie, out int iidParamIndex)
static unsafe void _GetPropertyProps(IntPtr scope, int mdToken, void **name, out int propertyAttributes, out ConstArray signature)
void EnumNestedTypes(int mdTypeDef, out MetadataEnumResult result)
void GetCustomAttributeProps(int customAttributeToken, out int constructorToken, out ConstArray signature)
unsafe string GetUserString(int mdToken)
unsafe MdUtf8String GetNamespace(int mdToken)
unsafe void GetPInvokeMap(int token, out PInvokeAttributes attributes, out string importName, out string importDll)
static bool _IsValidToken(IntPtr scope, int token)
static readonly MetadataImport EmptyImport
static void _GetSigOfMethodDef(IntPtr scope, int methodToken, ref ConstArray signature)
static void _GetScopeProps(IntPtr scope, out Guid mvid)
static void _GetGenericParamProps(IntPtr scope, int genericParameter, out int flags)
ConstArray GetSigOfFieldDef(int fieldToken)
unsafe void GetPropertyProps(int mdToken, out void *name, out PropertyAttributes propertyAttributes, out ConstArray signature)
void EnumParams(int mdMethodDef, out MetadataEnumResult result)
static void _GetSignatureFromToken(IntPtr scope, int methodToken, ref ConstArray signature)
void GetClassLayout(int typeTokenDef, out int packSize, out int classSize)
void Enum(MetadataTokenType type, int parent, out MetadataEnumResult result)
static unsafe void _GetName(IntPtr scope, int mdToken, void **name)
ConstArray GetFieldMarshal(int fieldToken)
void GetGenericParamProps(int genericParameter, out GenericParameterAttributes attributes)
void EnumCustomAttributes(int mdToken, out MetadataEnumResult result)
static unsafe void _GetNamespace(IntPtr scope, int mdToken, void **namesp)
void EnumProperties(int mdTypeDef, out MetadataEnumResult result)
static void _GetSigOfFieldDef(IntPtr scope, int fieldToken, ref ConstArray fieldMarshal)
override bool Equals(object obj)
ConstArray GetSignatureFromToken(int token)
void EnumEvents(int mdTypeDef, out MetadataEnumResult result)
ConstArray GetMemberRefProps(int memberTokenRef)
void EnumFields(int mdTypeDef, out MetadataEnumResult result)
void GetParamDefProps(int parameterToken, out int sequence, out ParameterAttributes attributes)
static void _GetParentToken(IntPtr scope, int mdToken, out int tkParent)
static string _GetDefaultValue(IntPtr scope, int mdToken, out long value, out int length, out int corElementType)
unsafe MdUtf8String GetName(int mdToken)
ConstArray GetSigOfMethodDef(int methodToken)
static void _GetFieldDefProps(IntPtr scope, int mdToken, out int fieldAttributes)
ConstArray GetMethodSignature(MetadataToken token)
static void _GetFieldMarshal(IntPtr scope, int fieldToken, ref ConstArray fieldMarshal)
static void _GetMemberRefProps(IntPtr scope, int memberTokenRef, out ConstArray signature)