Skip to content

Commit

Permalink
Fix bug where NoVersioningPolicy always fails version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
BadMagic100 committed Mar 29, 2023
1 parent ea4c7a5 commit 1007bbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
namespace RandoSettingsManager.SettingsManagement.Versioning
using System;

namespace RandoSettingsManager.SettingsManagement.Versioning
{
/// <summary>
/// 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).
/// </summary>
[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<object?>
{
/// <inheritdoc/>
public override object? Version => null;

/// <inheritdoc/>
protected override bool AllowsNullValues => true;

/// <inheritdoc/>
public override bool Allow(object? version) => true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public abstract class VersioningPolicy<T> : ISerializableVersioningPolicy
/// <returns>Whether the given version is allowed</returns>
public abstract bool Allow(T version);

/// <summary>
/// Used to determine whether null versions can be allowed. By default,
/// only allows null if the version type is Nullable&lt;T&gt;.
/// </summary>
protected virtual bool AllowsNullValues => Nullable.GetUnderlyingType(typeof(T)) != null;

string ISerializableVersioningPolicy.GetSerializedVersion(JsonConverter jsonConverter)
{
return jsonConverter.Serialize(Version);
Expand All @@ -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);
}
Expand Down

0 comments on commit 1007bbe

Please sign in to comment.