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

◆ GetCollectionSetItemDelegate< T >()

CollectionSetItemDelegate System.Runtime.Serialization.ReflectionReader.GetCollectionSetItemDelegate< T > ( CollectionDataContract collectionContract,
object resultCollectionObject,
bool isReadOnlyCollection )
inlineprivateinherited

Definition at line 435 of file ReflectionReader.cs.

436 {
437 if (isReadOnlyCollection && collectionContract.Kind == CollectionKind.Array)
438 {
439 int arraySize = ((Array)resultCollectionObject).Length;
440 return delegate(object resultCollection, object collectionItem, int index)
441 {
442 if (index == arraySize)
443 {
444 XmlObjectSerializerReadContext.ThrowArrayExceededSizeException(arraySize, collectionContract.UnderlyingType);
445 }
447 return resultCollection;
448 };
449 }
451 {
452 return delegate(object resultCollection, object collectionItem, int index)
453 {
454 resultCollection = XmlObjectSerializerReadContext.EnsureArraySize((T[])resultCollection, index);
456 return resultCollection;
457 };
458 }
459 if (collectionContract.Kind == CollectionKind.GenericDictionary || collectionContract.Kind == CollectionKind.Dictionary)
460 {
461 Type keyType2 = collectionContract.ItemType.GenericTypeArguments[0];
462 Type valueType2 = collectionContract.ItemType.GenericTypeArguments[1];
465 if (collectionContract.Kind == CollectionKind.GenericDictionary)
466 {
467 return delegate(object resultCollection, object collectionItem, int index)
468 {
471 collectionContract.AddMethod.Invoke(resultCollection, new object[2] { obj, obj2 });
472 return resultCollection;
473 };
474 }
475 return delegate(object resultCollection, object collectionItem, int index)
476 {
481 return resultCollection;
482 };
483 }
484 Type type = resultCollectionObject.GetType();
486 Type typeOfIList = Globals.TypeOfIList;
487 if (typeFromHandle.IsAssignableFrom(type))
488 {
489 return delegate(object resultCollection, object collectionItem, int index)
490 {
492 return resultCollection;
493 };
494 }
495 if (typeOfIList.IsAssignableFrom(type))
496 {
497 return delegate(object resultCollection, object collectionItem, int index)
498 {
500 return resultCollection;
501 };
502 }
504 if (addMethod == null)
505 {
506 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(System.SR.Format(System.SR.CollectionMustHaveAddMethod, DataContract.GetClrTypeFullName(collectionContract.UnderlyingType))));
507 }
508 return delegate(object resultCollection, object collectionItem, int index)
509 {
510 addMethod.Invoke(resultCollection, new object[1] { collectionItem });
511 return resultCollection;
512 };
513 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:MakeGenericMethod", Justification = "The call to MakeGenericMethod is safe due to the fact that ObjectToKeyValuePairGetKey and ObjectToKeyValuePairGetValue are not annotated.")]
514 static MethodInfo MakeGenericMethod(MethodInfo method, Type keyType, Type valueType)
515 {
516 return method.MakeGenericMethod(keyType, valueType);
517 }
518 }
void Add(TKey key, TValue value)
static readonly MethodInfo s_objectToKeyValuePairGetKey
bool IsArrayLikeCollection(CollectionDataContract collectionContract)
static readonly MethodInfo s_objectToKeyValuePairGetValue
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string CollectionMustHaveAddMethod
Definition SR.cs:36
Definition SR.cs:7

References System.Collections.Generic.Dictionary< TKey, TValue >.Dictionary(), System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.Runtime.Serialization.Array, System.SR.CollectionMustHaveAddMethod, System.dictionary, System.Runtime.Serialization.Dictionary, System.SR.Format(), System.Runtime.Serialization.DataContract.GetClrTypeFullName(), System.index, System.key, System.obj, System.T, System.Runtime.Serialization.XmlObjectSerializerReadContext.ThrowArrayExceededSizeException(), System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(), System.type, System.Runtime.Serialization.Globals.TypeOfIList, and System.value.