Version 3.3.1.2

SerializationPolicies class

Namespace: Sirenix.Serialization
Assembly: Sirenix.Serialization
public static class SerializationPolicies
Contains a set of default implementations of the Sirenix.Serialization.ISerializationPolicy interface.

NOTE: Policies are not necessarily compatible with each other in intuitive ways. Data serialized with the Everything policy will for example fail to deserialize auto-properties with Strict, even if only strict data is needed. It is best to ensure that you always use the same policy for serialization and deserialization.

This class and all of its policies are thread-safe.

Inheritance
  • System.Object
  • SerializationPolicies

Properties

Everything
All fields not marked with System.NonSerializedAttribute are serialized. If a field is marked with both System.NonSerializedAttribute and OdinSerializeAttribute, then the field will be serialized.
public static ISerializationPolicy Everything { get; }
Strict
Only fields and auto-properties marked with UnityEngine.SerializeField or OdinSerializeAttribute and not marked with System.NonSerializedAttribute are serialized.

There are two exceptions:

1) All fields in private nested types marked as compiler generated (e.g. lambda capture classes) are also serialized.

2) Virtual auto-properties are never serialized. Note that properties specified by an implemented interface are automatically marked virtual by the compiler.

public static ISerializationPolicy Strict { get; }
Unity
Public fields, as well as fields or auto-properties marked with UnityEngine.SerializeField or OdinSerializeAttribute and not marked with System.NonSerializedAttribute, are serialized.

There are two exceptions:

1) All fields in tuples, as well as in private nested types marked as compiler generated (e.g. lambda capture classes) are also serialized.

2) Virtual auto-properties are never serialized. Note that properties specified by an implemented interface are automatically marked virtual by the compiler.

public static ISerializationPolicy Unity { get; }

Methods

TryGetByID(String, out ISerializationPolicy)
Tries to get a serialization policy by its id, in case a serialization graph has the policy used for serialization stored by name.
public static bool TryGetByID(string name, out ISerializationPolicy policy)
Parameters
System.String name

Sirenix.Serialization.ISerializationPolicy policy

Returns
System.Boolean