using System; namespace UnityEngine.Rendering.HighDefinition { /// Define helpers to manipulate . static class MigrationStep { /// Create a new . /// An enum identifying the version. /// The type to migrate. /// The version of the step. /// The migration action to perform. /// The migration step. public static MigrationStep New(TVersion version, Action action) where TVersion : struct, IConvertible where TTarget : class, IVersionable { return new MigrationStep(version, action); } } /// Define a migration step. /// An enum identifying the version. /// The type to migrate. public struct MigrationStep : IEquatable> where TVersion : struct, IConvertible where TTarget : class, IVersionable { readonly Action m_MigrationAction; /// The version of the step. public readonly TVersion Version; /// Create a new migration step. /// The version of the step. /// The migration action to perform. public MigrationStep(TVersion version, Action action) { Version = version; m_MigrationAction = action; } /// /// Migrate the instance for this step and set the version of the instance to this version. /// /// If the instance has a version greater or equal to the step one, nothing will be applied. /// /// The instance to migrate. public void Migrate(TTarget target) { if ((int)(object)target.version >= (int)(object)Version) return; m_MigrationAction(target); target.version = Version; } /// Evaluate equality between migration steps. /// Other step to evaluate. /// True when the steps are equals. public bool Equals(MigrationStep other) { return Version.Equals(other.Version); } } }