Class DictionaryWithIdsSerializer
An implementation of CollectionWithIdsSerializerBase for dictionaries.
[YamlSerializerFactory(new string[] { "Assets" })]
public class DictionaryWithIdsSerializer : CollectionWithIdsSerializerBase, IYamlSerializable, IYamlSerializableFactory
- Inheritance
-
ObjectSerializerDictionarySerializerDictionaryWithIdsSerializer
- Implements
-
IYamlSerializableIYamlSerializableFactory
- Inherited Members
-
DictionarySerializer.ReadMember(ref ObjectContext)DictionarySerializer.WriteMembers(ref ObjectContext)ObjectSerializer.GetStyle(ref ObjectContext)ObjectSerializer.ReadMembers<TStart, TEnd>(ref ObjectContext)ObjectSerializer.WriteMember(ref ObjectContext, IMemberDescriptor)
Methods
CreatEmptyContainer(ITypeDescriptor)
Creates an empty dictionary that can store the mapping of ids to items of the collection.
protected override IDictionary CreatEmptyContainer(ITypeDescriptor descriptor)
Parameters
descriptorITypeDescriptorThe type descriptor of the collection for which to create the dictionary.
Returns
- IDictionary
An empty dictionary for mapping ids to elements.
ReadDeletedDictionaryItem(ref ObjectContext, object)
protected override KeyValuePair<object, object> ReadDeletedDictionaryItem(ref ObjectContext objectContext, object keyResult)
Parameters
objectContextObjectContextkeyResultobject
Returns
TransformAfterDeserialization(IDictionary, ITypeDescriptor, object, ICollection<ItemId>)
Transforms a dictionary containing the mapping of ids to items into the actual collection, and store the ids in the Stride.Core.Reflection.ShadowObject.
protected override void TransformAfterDeserialization(IDictionary container, ITypeDescriptor targetDescriptor, object targetCollection, ICollection<ItemId> deletedItems = null)
Parameters
containerIDictionaryThe dictionary mapping ids to item.
targetDescriptorITypeDescriptorThe type descriptor of the actual collection to fill.
targetCollectionobjectThe instance of the actual collection to fill.
deletedItemsICollection<ItemId>A collection of items that are marked as deleted. Can be null.
TransformForSerialization(ITypeDescriptor, object)
Transforms the given collection or dictionary into a dictionary of (ids, items) or a dictionary of (ids & keys, items).
protected override object TransformForSerialization(ITypeDescriptor descriptor, object collection)
Parameters
descriptorITypeDescriptorThe type descriptor of the collection.
collectionobjectThe collection for which to create the mapping dictionary.
Returns
- object
A dictionary mapping the id to the element of the initial collection.
TransformObjectAfterRead(ref ObjectContext)
Transforms the object after it has been read. This method is called after an object has been read and before returning the object to the deserialization process. See remarks for usage.
protected override void TransformObjectAfterRead(ref ObjectContext objectContext)
Parameters
objectContextObjectContext
Remarks
This method is usefull in conjunction with Stride.Core.Yaml.Serialization.Serializers.ObjectSerializer.CreateOrTransformObject(ref Stride.Core.Yaml.Serialization.ObjectContext). For example, in the case of deserializing to an immutable member, where we need to call the constructor of a type instead of setting each of its member, we can instantiate a mutable object in Stride.Core.Yaml.Serialization.Serializers.ObjectSerializer.CreateOrTransformObject(ref Stride.Core.Yaml.Serialization.ObjectContext), receive the mutable object filled in Stride.Core.Yaml.Serialization.Serializers.ObjectSerializer.TransformObjectAfterRead(ref Stride.Core.Yaml.Serialization.ObjectContext) and transform it back to an immutable object.
TryCreate(SerializerContext, ITypeDescriptor)
Try to create a Stride.Core.Yaml.Serialization.IYamlSerializable or return null if not supported for a particular .NET typeDescriptor.
public override IYamlSerializable TryCreate(SerializerContext context, ITypeDescriptor typeDescriptor)
Parameters
contextSerializerContexttypeDescriptorITypeDescriptorThe typeDescriptor.
Returns
- IYamlSerializable
If supported, return an instance of Stride.Core.Yaml.Serialization.IYamlSerializable else return
null.
WriteDeletedItems(ref ObjectContext)
protected override void WriteDeletedItems(ref ObjectContext objectContext)
Parameters
objectContextObjectContext