Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MethodBase.cs
Go to the documentation of this file.
6using System.Text;
8
9namespace System.Reflection;
10
11public abstract class MethodBase : MemberInfo
12{
13 private protected struct StackAllocedArguments
14 {
15 internal object _arg0;
16
17 private object _arg1;
18
19 private object _arg2;
20
21 private object _arg3;
22 }
23
24 public abstract MethodAttributes Attributes { get; }
25
27
29
30 public bool IsAbstract => (Attributes & MethodAttributes.Abstract) != 0;
31
32 public bool IsConstructor
33 {
34 get
35 {
36 if (this is ConstructorInfo && !IsStatic)
37 {
38 return (Attributes & MethodAttributes.RTSpecialName) == MethodAttributes.RTSpecialName;
39 }
40 return false;
41 }
42 }
43
44 public bool IsFinal => (Attributes & MethodAttributes.Final) != 0;
45
46 public bool IsHideBySig => (Attributes & MethodAttributes.HideBySig) != 0;
47
48 public bool IsSpecialName => (Attributes & MethodAttributes.SpecialName) != 0;
49
50 public bool IsStatic => (Attributes & MethodAttributes.Static) != 0;
51
52 public bool IsVirtual => (Attributes & MethodAttributes.Virtual) != 0;
53
54 public bool IsAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
55
56 public bool IsFamily => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
57
58 public bool IsFamilyAndAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
59
60 public bool IsFamilyOrAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
61
62 public bool IsPrivate => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
63
64 public bool IsPublic => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
65
66 public virtual bool IsConstructedGenericMethod
67 {
68 get
69 {
71 {
73 }
74 return false;
75 }
76 }
77
78 public virtual bool IsGenericMethod => false;
79
80 public virtual bool IsGenericMethodDefinition => false;
81
82 public virtual bool ContainsGenericParameters => false;
83
84 public abstract RuntimeMethodHandle MethodHandle { get; }
85
86 public virtual bool IsSecurityCritical
87 {
88 get
89 {
91 }
92 }
93
94 public virtual bool IsSecuritySafeCritical
95 {
96 get
97 {
99 }
100 }
101
102 public virtual bool IsSecurityTransparent
103 {
104 get
105 {
107 }
108 }
109
111 {
112 if (handle.IsNullHandle())
113 {
115 }
116 MethodBase methodBase = RuntimeType.GetMethodBase(handle.GetMethodInfo());
117 Type type = methodBase?.DeclaringType;
118 if (type != null && type.IsGenericType)
119 {
120 throw new ArgumentException(SR.Format(SR.Argument_MethodDeclaringTypeGeneric, methodBase, type.GetGenericTypeDefinition()));
121 }
122 return methodBase;
123 }
124
126 {
127 if (handle.IsNullHandle())
128 {
130 }
131 return RuntimeType.GetMethodBase(declaringType.GetRuntimeType(), handle.GetMethodInfo());
132 }
133
135 {
136 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
137 return RuntimeMethodInfo.InternalGetCurrentMethod(ref stackMark);
138 }
139
141 {
142 return MethodHandle.Value;
143 }
144
146 {
147 return GetParameters();
148 }
149
150 internal virtual Type[] GetParameterTypes()
151 {
152 ParameterInfo[] parametersNoCopy = GetParametersNoCopy();
153 Type[] array = new Type[parametersNoCopy.Length];
154 for (int i = 0; i < parametersNoCopy.Length; i++)
155 {
156 array[i] = parametersNoCopy[i].ParameterType;
157 }
158 return array;
159 }
160
161 private protected Span<object> CheckArguments(ref StackAllocedArguments stackArgs, ReadOnlySpan<object> parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
162 {
163 Span<object> result = ((parameters.Length <= 4) ? MemoryMarshal.CreateSpan(ref stackArgs._arg0, parameters.Length) : new Span<object>(new object[parameters.Length]));
164 ParameterInfo[] array = null;
165 for (int i = 0; i < parameters.Length; i++)
166 {
167 object obj = parameters[i];
168 RuntimeType runtimeType = sig.Arguments[i];
169 if (obj == Type.Missing)
170 {
171 if (array == null)
172 {
174 }
175 if (array[i].DefaultValue == DBNull.Value)
176 {
177 throw new ArgumentException(SR.Arg_VarMissNull, "parameters");
178 }
179 obj = array[i].DefaultValue;
180 }
181 result[i] = runtimeType.CheckValue(obj, binder, culture, invokeAttr);
182 }
183 return result;
184 }
185
186 public abstract ParameterInfo[] GetParameters();
187
189
190 [RequiresUnreferencedCode("Trimming may change method bodies. For example it can change some instructions, remove branches or local variables.")]
191 public virtual MethodBody? GetMethodBody()
192 {
193 throw new InvalidOperationException();
194 }
195
196 public virtual Type[] GetGenericArguments()
197 {
199 }
200
201 [DebuggerHidden]
202 [DebuggerStepThrough]
203 public object? Invoke(object? obj, object?[]? parameters)
204 {
205 return Invoke(obj, BindingFlags.Default, null, parameters, null);
206 }
207
208 public abstract object? Invoke(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture);
209
210 public override bool Equals(object? obj)
211 {
212 return base.Equals(obj);
213 }
214
215 public override int GetHashCode()
216 {
217 return base.GetHashCode();
218 }
219
220 [MethodImpl(MethodImplOptions.AggressiveInlining)]
221 public static bool operator ==(MethodBase? left, MethodBase? right)
222 {
223 if ((object)right == null)
224 {
225 if ((object)left != null)
226 {
227 return false;
228 }
229 return true;
230 }
231 if ((object)left == right)
232 {
233 return true;
234 }
235 return left?.Equals(right) ?? false;
236 }
237
238 public static bool operator !=(MethodBase? left, MethodBase? right)
239 {
240 return !(left == right);
241 }
242
243 internal static void AppendParameters(ref ValueStringBuilder sbParamList, Type[] parameterTypes, CallingConventions callingConvention)
244 {
245 string s = "";
246 foreach (Type type in parameterTypes)
247 {
248 sbParamList.Append(s);
249 string text = type.FormatTypeName();
250 if (type.IsByRef)
251 {
252 sbParamList.Append(text.AsSpan().TrimEnd('&'));
253 sbParamList.Append(" ByRef");
254 }
255 else
256 {
257 sbParamList.Append(text);
258 }
259 s = ", ";
260 }
261 if ((callingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
262 {
263 sbParamList.Append(s);
264 sbParamList.Append("...");
265 }
266 }
267}
static readonly DBNull Value
Definition DBNull.cs:8
static Exception ByDesign
virtual Type[] GetParameterTypes()
virtual bool IsSecuritySafeCritical
Definition MethodBase.cs:95
virtual MethodImplAttributes MethodImplementationFlags
Definition MethodBase.cs:26
static void AppendParameters(ref ValueStringBuilder sbParamList, Type[] parameterTypes, CallingConventions callingConvention)
virtual bool IsConstructedGenericMethod
Definition MethodBase.cs:67
virtual ? MethodBody GetMethodBody()
virtual bool IsGenericMethodDefinition
Definition MethodBase.cs:80
static ? MethodBase GetCurrentMethod()
object? Invoke(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture)
static bool operator==(MethodBase? left, MethodBase? right)
virtual bool IsSecurityCritical
Definition MethodBase.cs:87
ParameterInfo[] GetParameters()
object? Invoke(object? obj, object?[]? parameters)
MethodAttributes Attributes
Definition MethodBase.cs:24
virtual ParameterInfo[] GetParametersNoCopy()
static ? MethodBase GetMethodFromHandle(RuntimeMethodHandle handle)
static ? MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
Span< object > CheckArguments(ref StackAllocedArguments stackArgs, ReadOnlySpan< object > parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
RuntimeMethodHandle MethodHandle
Definition MethodBase.cs:84
MethodImplAttributes GetMethodImplementationFlags()
static bool operator!=(MethodBase? left, MethodBase? right)
virtual bool IsSecurityTransparent
override bool Equals(object? obj)
virtual bool ContainsGenericParameters
Definition MethodBase.cs:82
virtual Type[] GetGenericArguments()
static MethodBase InternalGetCurrentMethod(ref StackCrawlMark stackMark)
object CheckValue(object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
static MethodBase GetMethodBase(RuntimeModule scope, int typeMetadataToken)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Arg_VarMissNull
Definition SR.cs:448
static string Argument_InvalidHandle
Definition SR.cs:24
static string Argument_MethodDeclaringTypeGeneric
Definition SR.cs:760
static string NotSupported_SubclassOverride
Definition SR.cs:1714
Definition SR.cs:7
RuntimeType[] Arguments
Definition Signature.cs:29
static readonly object Missing
Definition Type.cs:21