Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RuntimeMethodInfo.cs
Go to the documentation of this file.
8using System.Text;
10
11namespace System.Reflection;
12
14{
16
18
19 private string m_name;
20
21 private string m_toString;
22
24
26
28
30
32
34
35 private object m_keepalive;
36
38
40 {
41 [MethodImpl(MethodImplOptions.AggressiveInlining)]
42 get
43 {
45 if ((iNVOCATION_FLAGS & INVOCATION_FLAGS.INVOCATION_FLAGS_INITIALIZED) == 0)
46 {
48 }
49 return iNVOCATION_FLAGS;
50 [MethodImpl(MethodImplOptions.NoInlining)]
52 {
53 INVOCATION_FLAGS iNVOCATION_FLAGS2 = INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN;
55 if (ContainsGenericParameters || IsDisallowedByRefType(ReturnType) || (declaringType != null && declaringType.ContainsGenericParameters) || (CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
56 {
57 iNVOCATION_FLAGS2 = INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE;
58 }
59 else if ((declaringType != null && declaringType.IsByRefLike) || ReturnType.IsByRefLike)
60 {
61 iNVOCATION_FLAGS2 |= INVOCATION_FLAGS.INVOCATION_FLAGS_CONTAINS_STACK_POINTERS;
62 }
63 return m_invocationFlags = iNVOCATION_FLAGS2 | INVOCATION_FLAGS.INVOCATION_FLAGS_INITIALIZED;
64 }
65 }
66 }
67
69
71
73 {
74 [MethodImpl(MethodImplOptions.AggressiveInlining)]
75 get
76 {
78 [MethodImpl(MethodImplOptions.NoInlining)]
80 {
83 return signature;
84 }
85 }
86 }
87
89
91
92 public override string Name => m_name ?? (m_name = RuntimeMethodHandle.GetName(this));
93
94 public override Type DeclaringType
95 {
96 get
97 {
98 if (m_reflectedTypeCache.IsGlobal)
99 {
100 return null;
101 }
102 return m_declaringType;
103 }
104 }
105
106 public override Type ReflectedType
107 {
108 get
109 {
110 if (m_reflectedTypeCache.IsGlobal)
111 {
112 return null;
113 }
114 return m_reflectedTypeCache.GetRuntimeType();
115 }
116 }
117
118 public override MemberTypes MemberType => MemberTypes.Method;
119
120 public override int MetadataToken => RuntimeMethodHandle.GetMethodDef(this);
121
122 public override Module Module => GetRuntimeModule();
123
124 public override bool IsSecurityCritical => true;
125
126 public override bool IsSecuritySafeCritical => false;
127
128 public override bool IsSecurityTransparent => false;
129
131
133
134 public override CallingConventions CallingConvention => Signature.CallingConvention;
135
137
139
141
143
145
147
148 public override bool ContainsGenericParameters
149 {
150 get
151 {
152 if (DeclaringType != null && DeclaringType.ContainsGenericParameters)
153 {
154 return true;
155 }
156 if (!IsGenericMethod)
157 {
158 return false;
159 }
161 for (int i = 0; i < genericArguments.Length; i++)
162 {
164 {
165 return true;
166 }
167 }
168 return false;
169 }
170 }
171
172 private static bool IsDisallowedByRefType(Type type)
173 {
174 if (!type.IsByRef)
175 {
176 return false;
177 }
179 if (!elementType.IsByRefLike)
180 {
181 return elementType == typeof(void);
182 }
183 return true;
184 }
185
195
200
205
206 internal override bool CacheEquals(object o)
207 {
209 {
210 return runtimeMethodInfo.m_handle == m_handle;
211 }
212 return false;
213 }
214
216 {
217 if (!base.IsVirtual || m_declaringType.IsInterface)
218 {
219 return null;
220 }
222 if (runtimeType == null)
223 {
224 return null;
225 }
226 int slot = RuntimeMethodHandle.GetSlot(this);
228 {
229 return null;
230 }
232 }
233
235 {
236 return m_declaringType;
237 }
238
239 public override string ToString()
240 {
241 if (m_toString == null)
242 {
244 sbParamList.Append(ReturnType.FormatTypeName());
245 sbParamList.Append(' ');
246 sbParamList.Append(Name);
247 if (IsGenericMethod)
248 {
250 }
251 sbParamList.Append('(');
253 sbParamList.Append(')');
254 m_toString = sbParamList.ToString();
255 }
256 return m_toString;
257 }
258
259 public override int GetHashCode()
260 {
261 if (IsGenericMethod)
262 {
264 }
265 return base.GetHashCode();
266 }
267
268 public override bool Equals(object obj)
269 {
270 if (!IsGenericMethod)
271 {
272 return obj == this;
273 }
275 if (runtimeMethodInfo == null || !runtimeMethodInfo.IsGenericMethod)
276 {
277 return false;
278 }
281 if (runtimeMethodInfo2.Value.Value != runtimeMethodInfo3.Value.Value)
282 {
283 return false;
284 }
286 Type[] genericArguments2 = runtimeMethodInfo.GetGenericArguments();
287 if (genericArguments.Length != genericArguments2.Length)
288 {
289 return false;
290 }
291 for (int i = 0; i < genericArguments.Length; i++)
292 {
294 {
295 return false;
296 }
297 }
298 if (DeclaringType != runtimeMethodInfo.DeclaringType)
299 {
300 return false;
301 }
302 if (ReflectedType != runtimeMethodInfo.ReflectedType)
303 {
304 return false;
305 }
306 return true;
307 }
308
309 public override object[] GetCustomAttributes(bool inherit)
310 {
312 }
313
314 public override object[] GetCustomAttributes(Type attributeType, bool inherit)
315 {
316 if (attributeType == null)
317 {
318 throw new ArgumentNullException("attributeType");
319 }
320 RuntimeType runtimeType = attributeType.UnderlyingSystemType as RuntimeType;
321 if (runtimeType == null)
322 {
323 throw new ArgumentException(SR.Arg_MustBeType, "attributeType");
324 }
326 }
327
328 public override bool IsDefined(Type attributeType, bool inherit)
329 {
330 if (attributeType == null)
331 {
332 throw new ArgumentNullException("attributeType");
333 }
334 RuntimeType runtimeType = attributeType.UnderlyingSystemType as RuntimeType;
335 if (runtimeType == null)
336 {
337 throw new ArgumentException(SR.Arg_MustBeType, "attributeType");
338 }
340 }
341
346
351
353 {
354 return m_declaringType;
355 }
356
361
362 internal override ParameterInfo[] GetParametersNoCopy()
363 {
365 }
366
367 public override ParameterInfo[] GetParameters()
368 {
370 if (array.Length == 0)
371 {
372 return array;
373 }
374 ParameterInfo[] array2 = new ParameterInfo[array.Length];
375 Array.Copy(array, array2, array.Length);
376 return array2;
377 }
378
383
384 [RequiresUnreferencedCode("Trimming may change method bodies. For example it can change some instructions, remove branches or local variables.")]
385 public override MethodBody GetMethodBody()
386 {
388 if (methodBody != null)
389 {
390 methodBody._methodBase = this;
391 }
392 return methodBody;
393 }
394
395 [MethodImpl(MethodImplOptions.AggressiveInlining)]
396 private void CheckConsistency(object target)
397 {
399 {
400 if (target == null)
401 {
403 }
405 }
406 }
407
410 {
411 if ((InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_CONTAINS_STACK_POINTERS) != 0)
412 {
413 throw new NotSupportedException();
414 }
415 if ((CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
416 {
417 throw new NotSupportedException();
418 }
419 if (DeclaringType.ContainsGenericParameters || ContainsGenericParameters)
420 {
422 }
423 if (base.IsAbstract)
424 {
425 throw new MemberAccessException();
426 }
427 if (ReturnType.IsByRef)
428 {
429 Type elementType = ReturnType.GetElementType();
430 if (elementType.IsByRefLike)
431 {
433 }
434 if (elementType == typeof(void))
435 {
437 }
438 }
439 throw new TargetException();
440 }
441
443 [DebuggerHidden]
444 public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
445 {
446 if ((InvocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE | INVOCATION_FLAGS.INVOCATION_FLAGS_CONTAINS_STACK_POINTERS)) != 0)
447 {
449 }
452 int num = ((parameters != null) ? parameters.Length : 0);
453 if (signature.Arguments.Length != num)
454 {
456 }
459 if (num != 0)
460 {
462 }
463 bool wrapExceptions = (invokeAttr & BindingFlags.DoNotWrapExceptions) == 0;
465 for (int i = 0; i < arguments.Length; i++)
466 {
467 parameters[i] = arguments[i];
468 }
469 return result;
470 }
471
473 [DebuggerHidden]
475 {
476 if ((InvocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE | INVOCATION_FLAGS.INVOCATION_FLAGS_CONTAINS_STACK_POINTERS)) != 0)
477 {
479 }
482 if (signature.Arguments.Length != 1)
483 {
485 }
488 bool wrapExceptions = (invokeAttr & BindingFlags.DoNotWrapExceptions) == 0;
490 }
491
516
521
522 public override Delegate CreateDelegate(Type delegateType, object target)
523 {
524 return CreateDelegateInternal(delegateType, target, DelegateBindingFlags.RelaxedSignature);
525 }
526
528 {
529 if (delegateType == null)
530 {
531 throw new ArgumentNullException("delegateType");
532 }
534 if (runtimeType == null)
535 {
536 throw new ArgumentException(SR.Argument_MustBeRuntimeType, "delegateType");
537 }
538 if (!runtimeType.IsDelegate())
539 {
540 throw new ArgumentException(SR.Arg_MustBeDelegate, "delegateType");
541 }
543 if ((object)@delegate == null)
544 {
546 }
547 return @delegate;
548 }
549
550 [RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
552 {
553 if (methodInstantiation == null)
554 {
555 throw new ArgumentNullException("methodInstantiation");
556 }
559 {
561 }
562 for (int i = 0; i < methodInstantiation.Length; i++)
563 {
565 if (type == null)
566 {
567 throw new ArgumentNullException();
568 }
570 if (runtimeType == null)
571 {
572 Type[] array2 = new Type[methodInstantiation.Length];
573 for (int j = 0; j < methodInstantiation.Length; j++)
574 {
576 }
579 }
580 array[i] = runtimeType;
581 }
584 MethodInfo methodInfo = null;
585 try
586 {
588 }
589 catch (VerificationException e)
590 {
592 throw;
593 }
594 }
595
600
601 public override Type[] GetGenericArguments()
602 {
604 }
605
614
624}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static Delegate CreateDelegateInternal(RuntimeType rtType, RuntimeMethodInfo rtMethod, object firstArgument, DelegateBindingFlags flags)
Definition Delegate.cs:314
static object[] GetCustomAttributes(RuntimeType type, RuntimeType caType, bool inherit)
static bool IsDefined(RuntimeType type, RuntimeType caType, bool inherit)
static MethodInfo MakeGenericMethod(MethodInfo method, Type[] inst)
virtual Type[] GetParameterTypes()
static void AppendParameters(ref ValueStringBuilder sbParamList, Type[] parameterTypes, CallingConventions callingConvention)
Span< object > CheckArguments(ref StackAllocedArguments stackArgs, ReadOnlySpan< object > parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
static IList< CustomAttributeData > GetCustomAttributesInternal(RuntimeType target)
RuntimeType.RuntimeTypeCache m_reflectedTypeCache
override ParameterInfo[] GetParametersNoCopy()
override bool HasSameMetadataDefinitionAs(MemberInfo other)
override MethodAttributes Attributes
RuntimeMethodInfo(RuntimeMethodHandleInternal handle, RuntimeType declaringType, RuntimeType.RuntimeTypeCache reflectedTypeCache, MethodAttributes methodAttributes, BindingFlags bindingFlags, object keepalive)
override object[] GetCustomAttributes(bool inherit)
override Delegate CreateDelegate(Type delegateType, object target)
override RuntimeMethodHandle MethodHandle
override IList< CustomAttributeData > GetCustomAttributesData()
object InvokeOneParameter(object obj, BindingFlags invokeAttr, Binder binder, object parameter, CultureInfo culture)
override object[] GetCustomAttributes(Type attributeType, bool inherit)
override Delegate CreateDelegate(Type delegateType)
override ParameterInfo[] GetParameters()
override bool IsDefined(Type attributeType, bool inherit)
override MethodInfo MakeGenericMethod(params Type[] methodInstantiation)
override ICustomAttributeProvider ReturnTypeCustomAttributes
override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
override MethodImplAttributes GetMethodImplementationFlags()
override MethodInfo GetGenericMethodDefinition()
Delegate CreateDelegateInternal(Type delegateType, object firstArgument, DelegateBindingFlags bindingFlags)
static MethodBase InternalGetCurrentMethod(ref StackCrawlMark stackMark)
static bool IsDisallowedByRefType(Type type)
static ParameterInfo GetReturnParameter(IRuntimeMethodInfo method, MemberInfo member, Signature sig)
static ParameterInfo[] GetParameters(IRuntimeMethodInfo method, MemberInfo member, Signature sig)
override bool IsInstanceOfType([NotNullWhen(true)] object o)
override Type BaseType
static void SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParameters)
RuntimeModule GetRuntimeModule()
static void ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
static MethodBase GetMethodBase(RuntimeModule scope, int typeMetadataToken)
static string Arg_NotGenericMethodDefinition
Definition SR.cs:344
static string Arg_MustBeType
Definition SR.cs:302
static string NotSupported_ByRefToVoidReturn
Definition SR.cs:1654
static string Arg_UnboundGenParam
Definition SR.cs:444
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string RFLCT_Targ_ITargMismatch
Definition SR.cs:1846
static string Arg_MustBeDelegate
Definition SR.cs:268
static string Arg_DlgtTargMeth
Definition SR.cs:122
static string Arg_ParmCnt
Definition SR.cs:368
static string RFLCT_Targ_StatMethReqTarg
Definition SR.cs:1850
static string NotSupported_ByRefToByRefLikeReturn
Definition SR.cs:1652
static string Argument_MustBeRuntimeType
Definition SR.cs:782
Definition SR.cs:7
RuntimeType ReturnType
Definition Signature.cs:31
CallingConventions CallingConvention
Definition Signature.cs:27
static void Write(ref bool location, bool value)
Definition Volatile.cs:74
Type? GetElementType()
bool IsInterface
Definition Type.cs:30
static readonly Type[] EmptyTypes
Definition Type.cs:19
static int GetHashCodeOfPtr(IntPtr ptr)
static int GetMethodDef(IRuntimeMethodInfo method)
static RuntimeType[] GetMethodInstantiationInternal(IRuntimeMethodInfo method)
static int GetGenericParameterCount(RuntimeMethodHandleInternal method)
static Type[] GetMethodInstantiationPublic(IRuntimeMethodInfo method)
static IRuntimeMethodInfo GetCurrentMethod(ref StackCrawlMark stackMark)
static bool HasMethodInstantiation(RuntimeMethodHandleInternal method)
static Interop.BOOL GetIsCollectible(RuntimeMethodHandleInternal handle)
static void StripMethodInstantiation(RuntimeMethodHandleInternal method, ObjectHandleOnStack outMethod)
static string GetName(RuntimeMethodHandleInternal method)
static MethodImplAttributes GetImplAttributes(IRuntimeMethodInfo method)
static void ConstructInstantiation(RuntimeMethodHandleInternal method, TypeNameFormatFlags format, StringHandleOnStack retString)
static RuntimeMethodBody GetMethodBody(IRuntimeMethodInfo method, RuntimeType declaringType)
static int GetSlot(RuntimeMethodHandleInternal method)
static object InvokeMethod(object target, in Span< object > arguments, Signature sig, bool constructor, bool wrapExceptions)
static bool IsGenericMethodDefinition(RuntimeMethodHandleInternal method)
static RuntimeMethodHandleInternal GetStubIfNeeded(RuntimeMethodHandleInternal method, RuntimeType declaringType, RuntimeType[] methodInstantiation)
static RuntimeMethodHandleInternal GetMethodAt(RuntimeType type, int slot)
static int GetNumVirtuals(RuntimeType type)