Table of Contents

Class CollectionWithIdsSerializerBase

Namespace
Stride.Core.Yaml
Assembly
Stride.Core.Assets.dll

A base class to serialize collections with unique identifiers for each item.

[YamlSerializerFactory(new string[] { "Assets" })]
public abstract class CollectionWithIdsSerializerBase : DictionarySerializer, IYamlSerializable, IYamlSerializableFactory
Inheritance
ObjectSerializer
DictionarySerializer
CollectionWithIdsSerializerBase
Implements
IYamlSerializable
IYamlSerializableFactory
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

PropertyKey<ICollection<ItemId>>

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

PropertyKey<CollectionWithIdsSerializerBase.InstanceInfo>

NonIdentifiableCollectionItemsKey

A property key to indicate whether a collection has non-identifiable items

public static readonly PropertyKey<bool> NonIdentifiableCollectionItemsKey

Field Value

PropertyKey<bool>

YamlDeletedKey

A string token to identify deleted items in a collection.

public const string YamlDeletedKey = "~(Deleted)"

Field Value

string

Methods

AreCollectionItemsIdentifiable(ref ObjectContext)

protected static bool AreCollectionItemsIdentifiable(ref ObjectContext objectContext)

Parameters

objectContext ObjectContext

Returns

bool

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 ITypeDescriptor

The 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 ObjectContext

The object context.

ReadDeletedDictionaryItem(ref ObjectContext, object)

protected abstract KeyValuePair<object, object> ReadDeletedDictionaryItem(ref ObjectContext objectContext, object keyResult)

Parameters

objectContext ObjectContext
keyResult object

Returns

KeyValuePair<object, object>

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 ObjectContext

The 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 ObjectContext
transformed 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 IDictionary

The dictionary mapping ids to item.

targetDescriptor ITypeDescriptor

The type descriptor of the actual collection to fill.

targetCollection object

The 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 ITypeDescriptor

The type descriptor of the collection.

collection object

The 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 ObjectContext

The object context.

WriteYaml(ref ObjectContext)

Writes the specified object context to a YAML emitter.

public override void WriteYaml(ref ObjectContext objectContext)

Parameters

objectContext ObjectContext

The object context.

WriteYamlAfterTransform(ref ObjectContext, bool)

protected virtual void WriteYamlAfterTransform(ref ObjectContext objectContext, bool transformed)

Parameters

objectContext ObjectContext
transformed bool