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

◆ CreateInstanceImpl()

object System.RuntimeType.CreateInstanceImpl ( BindingFlags bindingAttr,
Binder binder,
object[] args,
CultureInfo culture )
inlinepackage

Definition at line 3116 of file RuntimeType.cs.

3117 {
3119 if (args == null)
3120 {
3121 args = Array.Empty<object>();
3122 }
3123 if (binder == null)
3124 {
3125 binder = Type.DefaultBinder;
3126 }
3127 bool publicOnly = (bindingAttr & BindingFlags.NonPublic) == 0;
3128 bool wrapExceptions = (bindingAttr & BindingFlags.DoNotWrapExceptions) == 0;
3129 object result;
3130 if (args.Length == 0 && (bindingAttr & BindingFlags.Public) != 0 && (bindingAttr & BindingFlags.Instance) != 0 && (IsGenericCOMObjectImpl() || base.IsValueType))
3131 {
3133 }
3134 else
3135 {
3138 Type[] array = new Type[args.Length];
3139 for (int i = 0; i < args.Length; i++)
3140 {
3141 object obj = args[i];
3142 if (obj != null)
3143 {
3144 array[i] = obj.GetType();
3145 }
3146 }
3147 for (int j = 0; j < constructors.Length; j++)
3148 {
3150 {
3152 }
3153 }
3154 if (list.Count == 0)
3155 {
3156 throw new MissingMethodException(SR.Format(SR.MissingConstructor_Name, FullName));
3157 }
3158 MethodBase[] match = list.ToArray();
3159 object state = null;
3161 try
3162 {
3163 methodBase = binder.BindToMethod(bindingAttr, match, ref args, null, culture, null, out state);
3164 }
3165 catch (MissingMethodException)
3166 {
3167 methodBase = null;
3168 }
3169 if ((object)methodBase == null)
3170 {
3171 throw new MissingMethodException(SR.Format(SR.MissingConstructor_Name, FullName));
3172 }
3173 if (methodBase.GetParametersNoCopy().Length == 0)
3174 {
3175 if (args.Length != 0)
3176 {
3177 throw new NotSupportedException(SR.NotSupported_CallToVarArg);
3178 }
3179 result = Activator.CreateInstance(this, nonPublic: true, wrapExceptions);
3180 }
3181 else
3182 {
3184 if (state != null)
3185 {
3186 binder.ReorderArgumentArray(ref args, state);
3187 }
3188 }
3189 }
3190 return result;
3191 }
void Add(TKey key, TValue value)
object CreateInstanceDefaultCtor(bool publicOnly, bool wrapExceptions)
bool IsGenericCOMObjectImpl()
static bool FilterApplyConstructorInfo(RuntimeConstructorInfo constructor, BindingFlags bindingFlags, CallingConventions callConv, Type[] argumentTypes)
override string FullName
void CreateInstanceCheckThis()
ConstructorInfo[] GetConstructors()
Definition Type.cs:580

References System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.array, System.Activator.CreateInstance(), System.RuntimeType.CreateInstanceCheckThis(), System.RuntimeType.CreateInstanceDefaultCtor(), System.culture, System.Type.DefaultBinder, System.RuntimeType.FilterApplyConstructorInfo(), System.SR.Format(), System.RuntimeType.FullName, System.Type.GetConstructors(), System.RuntimeType.IsGenericCOMObjectImpl(), System.list, System.match, System.SR.MissingConstructor_Name, System.SR.NotSupported_CallToVarArg, System.obj, and System.state.