diff --git a/RandoSettingsManager/SettingsManagement/Versioning/NoVersioningPolicy.cs b/RandoSettingsManager/SettingsManagement/Versioning/NoVersioningPolicy.cs index 4d0c5e3..19065d6 100644 --- a/RandoSettingsManager/SettingsManagement/Versioning/NoVersioningPolicy.cs +++ b/RandoSettingsManager/SettingsManagement/Versioning/NoVersioningPolicy.cs @@ -1,15 +1,22 @@ -namespace RandoSettingsManager.SettingsManagement.Versioning +using System; + +namespace RandoSettingsManager.SettingsManagement.Versioning { /// /// A versioning policy that performs no version checking. Using this versioning policy /// implies indefinite backwards compatibility of settings and logic (failing to meet this promise /// may cause settings to fail to load or hash mismatches). /// + [Obsolete("This versioning policy is not recommended for most used cases. " + + "Consider StrictModVersioningPolicy if you're just looking for a simple-to-use policy.")] public class NoVersioningPolicy : VersioningPolicy { /// public override object? Version => null; + /// + protected override bool AllowsNullValues => true; + /// public override bool Allow(object? version) => true; } diff --git a/RandoSettingsManager/SettingsManagement/Versioning/VersioningPolicy.cs b/RandoSettingsManager/SettingsManagement/Versioning/VersioningPolicy.cs index 993016c..6eee50d 100644 --- a/RandoSettingsManager/SettingsManagement/Versioning/VersioningPolicy.cs +++ b/RandoSettingsManager/SettingsManagement/Versioning/VersioningPolicy.cs @@ -39,6 +39,12 @@ public abstract class VersioningPolicy : ISerializableVersioningPolicy /// Whether the given version is allowed public abstract bool Allow(T version); + /// + /// Used to determine whether null versions can be allowed. By default, + /// only allows null if the version type is Nullable<T>. + /// + protected virtual bool AllowsNullValues => Nullable.GetUnderlyingType(typeof(T)) != null; + string ISerializableVersioningPolicy.GetSerializedVersion(JsonConverter jsonConverter) { return jsonConverter.Serialize(Version); @@ -60,7 +66,7 @@ bool ISerializableVersioningPolicy.AllowSerialized(JsonConverter jsonConverter, // if we're unable to recognize the type, of course we cannot allow the provided version if (ver == null) { - return false; + return AllowsNullValues; } return Allow(ver); }