Class CollectionWithIdsSerializerBase
A base class to serialize collections with unique identifiers for each item.
[YamlSerializerFactory(new string[] { "Assets" })]
public abstract class CollectionWithIdsSerializerBase : DictionarySerializer, IYamlSerializable, IYamlSerializableFactory
- Inheritance
-
ObjectSerializerDictionarySerializerCollectionWithIdsSerializerBase
- Implements
-
IYamlSerializableIYamlSerializableFactory
- Derived
- Inherited Members
-
DictionarySerializer.TryCreate(SerializerContext, ITypeDescriptor)DictionarySerializer.ReadMember(ref ObjectContext)DictionarySerializer.WriteMembers(ref ObjectContext)ObjectSerializer.GetStyle(ref ObjectContext)ObjectSerializer.TransformObjectAfterRead(ref ObjectContext)ObjectSerializer.ReadMembers<TStart, TEnd>(ref ObjectContext)ObjectSerializer.WriteMember(ref ObjectContext, IMemberDescriptor)
Fields
DeletedItemsKey
A key that identifies deleted items during deserialization.
protected static readonly PropertyKey<ICollection<ItemId>> DeletedItemsKey
Field Value
InstanceInfoKey
A key that identifies the information about the instance that we need the store in the Stride.Core.Yaml.Serialization.ObjectContext.Properties dictionary.
protected static readonly PropertyKey<CollectionWithIdsSerializerBase.InstanceInfo> InstanceInfoKey
Field Value
NonIdentifiableCollectionItemsKey
A property key to indicate whether a collection has non-identifiable items
public static readonly PropertyKey<bool> NonIdentifiableCollectionItemsKey
Field Value
YamlDeletedKey
A string token to identify deleted items in a collection.
public const string YamlDeletedKey = "~(Deleted)"
Field Value
Methods
AreCollectionItemsIdentifiable(ref ObjectContext)
protected static bool AreCollectionItemsIdentifiable(ref ObjectContext objectContext)
Parameters
objectContext
ObjectContext
Returns
CheckIsSequence(ref ObjectContext)
Checks if a type is a sequence.
protected override bool CheckIsSequence(ref ObjectContext objectContext)
Parameters
objectContext
ObjectContext
Returns
- bool
true
if a type is a sequence,false
otherwise.
CreatEmptyContainer(ITypeDescriptor)
Creates an empty dictionary that can store the mapping of ids to items of the collection.
protected abstract IDictionary CreatEmptyContainer(ITypeDescriptor descriptor)
Parameters
descriptor
ITypeDescriptorThe type descriptor of the collection for which to create the dictionary.
Returns
- IDictionary
An empty dictionary for mapping ids to elements.
CreateOrTransformObject(ref ObjectContext)
Overrides this method when deserializing/serializing an object that needs a special instantiation or transformation. By default, this is calling Create(Type) if the Stride.Core.Yaml.Serialization.ObjectContext.Instance is null or returning Stride.Core.Yaml.Serialization.ObjectContext.Instance.
protected override void CreateOrTransformObject(ref ObjectContext objectContext)
Parameters
objectContext
ObjectContextThe object context.
ReadDeletedDictionaryItem(ref ObjectContext, object)
protected abstract KeyValuePair<object, object> ReadDeletedDictionaryItem(ref ObjectContext objectContext, object keyResult)
Parameters
objectContext
ObjectContextkeyResult
object
Returns
ReadDictionaryItem(ref ObjectContext, KeyValuePair<Type, Type>)
Reads a dictionary item key-value.
protected override KeyValuePair<object, object> ReadDictionaryItem(ref ObjectContext objectContext, KeyValuePair<Type, Type> keyValueTypes)
Parameters
objectContext
ObjectContextThe object context.
keyValueTypes
KeyValuePair<Type, Type>The types corresponding to the key and the value.
Returns
- KeyValuePair<object, object>
A KeyValuePair<TKey, TValue> representing the dictionary item.
ReadDictionaryItems(ref ObjectContext)
Reads the dictionary items key-values.
protected override void ReadDictionaryItems(ref ObjectContext objectContext)
Parameters
objectContext
ObjectContext
ReadYaml(ref ObjectContext)
Reads this object's state from a YAML parser.
public override object ReadYaml(ref ObjectContext objectContext)
Parameters
objectContext
ObjectContext
Returns
- object
A instance of the object deserialized from Yaml.
ReadYamlAfterTransform(ref ObjectContext, bool)
protected virtual void ReadYamlAfterTransform(ref ObjectContext objectContext, bool transformed)
Parameters
objectContext
ObjectContexttransformed
bool
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 abstract void TransformAfterDeserialization(IDictionary container, ITypeDescriptor targetDescriptor, object targetCollection, ICollection<ItemId> deletedItems = null)
Parameters
container
IDictionaryThe dictionary mapping ids to item.
targetDescriptor
ITypeDescriptorThe type descriptor of the actual collection to fill.
targetCollection
objectThe instance of the actual collection to fill.
deletedItems
ICollection<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 abstract object TransformForSerialization(ITypeDescriptor descriptor, object collection)
Parameters
descriptor
ITypeDescriptorThe type descriptor of the collection.
collection
objectThe collection for which to create the mapping dictionary.
Returns
- object
A dictionary mapping the id to the element of the initial collection.
WriteDeletedItems(ref ObjectContext)
protected abstract void WriteDeletedItems(ref ObjectContext objectContext)
Parameters
objectContext
ObjectContext
WriteDictionaryItems(ref ObjectContext)
Writes the dictionary items keys-values.
protected override void WriteDictionaryItems(ref ObjectContext objectContext)
Parameters
objectContext
ObjectContextThe object context.
WriteYaml(ref ObjectContext)
Writes the specified object context to a YAML emitter.
public override void WriteYaml(ref ObjectContext objectContext)
Parameters
objectContext
ObjectContextThe object context.
WriteYamlAfterTransform(ref ObjectContext, bool)
protected virtual void WriteYamlAfterTransform(ref ObjectContext objectContext, bool transformed)
Parameters
objectContext
ObjectContexttransformed
bool