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

◆ BindToField() [1/2]

override FieldInfo System.DefaultBinder.BindToField ( BindingFlags bindingAttr,
FieldInfo[] match,
object value,
CultureInfo cultureInfo )
inlinesealedinherited

Definition at line 336 of file DefaultBinder.cs.

337 {
338 if (match == null)
339 {
340 throw new ArgumentNullException("match");
341 }
342 int num = 0;
343 FieldInfo[] array = (FieldInfo[])match.Clone();
344 if ((bindingAttr & BindingFlags.SetField) != 0)
345 {
346 Type type = value.GetType();
347 for (int i = 0; i < array.Length; i++)
348 {
349 Type fieldType = array[i].FieldType;
350 if (fieldType == type)
351 {
352 array[num++] = array[i];
353 }
354 else if (value == Empty.Value && fieldType.IsClass)
355 {
356 array[num++] = array[i];
357 }
358 else if (fieldType == typeof(object))
359 {
360 array[num++] = array[i];
361 }
362 else if (fieldType.IsPrimitive)
363 {
364 if (CanChangePrimitive(type, fieldType))
365 {
366 array[num++] = array[i];
367 }
368 }
369 else if (fieldType.IsAssignableFrom(type))
370 {
371 array[num++] = array[i];
372 }
373 }
374 switch (num)
375 {
376 case 0:
377 throw new MissingFieldException(SR.MissingField);
378 case 1:
379 return array[0];
380 }
381 }
382 int num2 = 0;
383 bool flag = false;
384 for (int i = 1; i < num; i++)
385 {
386 switch (FindMostSpecificField(array[num2], array[i]))
387 {
388 case 0:
389 flag = true;
390 break;
391 case 2:
392 num2 = i;
393 flag = false;
394 break;
395 }
396 }
397 if (flag)
398 {
399 throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
400 }
401 return array[num2];
402 }
static bool CanChangePrimitive(Type source, Type target)
static int FindMostSpecificField(FieldInfo cur1, FieldInfo cur2)

References System.SR.Arg_AmbiguousMatchException, System.array, System.DefaultBinder.CanChangePrimitive(), System.DefaultBinder.FindMostSpecificField(), System.Type.GetType(), System.Type.IsAssignableFrom(), System.Type.IsClass, System.Type.IsPrimitive, System.match, System.SR.MissingField, System.type, System.Empty.Value, and System.value.