Browse Source

Added an AlmostVersionConverter

pull/46/head
Anairkoen Schno 4 years ago
parent
commit
d631d39474
4 changed files with 30 additions and 3 deletions
  1. +1
    -1
      IPA.Loader/Config/Stores/CustomObjectConverter.cs
  2. +1
    -0
      IPA.Loader/Loader/PluginManifest.cs
  3. +1
    -1
      IPA.Loader/Updating/BeatMods/ApiEndpoint.cs
  4. +27
    -1
      IPA.Loader/Utilities/AlmostVersion.cs

+ 1
- 1
IPA.Loader/Config/Stores/CustomObjectConverter.cs View File

@ -20,7 +20,7 @@ namespace IPA.Config.Stores.Converters
private static readonly GeneratedStore.GeneratedStoreCreator creator = GeneratedStore.GetCreator(typeof(T));
public T FromValue(Value value, object parent)
{ // lots of casting here, but it works i promise (parent can be a non-IGeneratedStore, however it won't necessarily behave then)
{ // lots of casting here, but it works i promise (probably) (parent can be a non-IGeneratedStore, however it won't necessarily behave then)
var obj = creator(parent as GeneratedStore.IGeneratedStore) as U;
obj.Deserialize(value);
return obj;


+ 1
- 0
IPA.Loader/Loader/PluginManifest.cs View File

@ -4,6 +4,7 @@ using Newtonsoft.Json;
using SemVer;
using System;
using System.Collections.Generic;
using AlmostVersionConverter = IPA.JsonConverters.AlmostVersionConverter;
using Version = SemVer.Version;
namespace IPA.Loader


+ 1
- 1
IPA.Loader/Updating/BeatMods/ApiEndpoint.cs View File

@ -104,7 +104,7 @@ namespace IPA.Updating.BeatMods
public Version Version;
[JsonProperty("gameVersion"),
JsonConverter(typeof(AlmostVersionConverter))]
JsonConverter(typeof(JsonConverters.AlmostVersionConverter))]
public AlmostVersion GameVersion;
[Serializable]


+ 27
- 1
IPA.Loader/Utilities/AlmostVersion.cs View File

@ -1,4 +1,7 @@
using System;
using IPA.Config.Data;
using IPA.Config.Stores;
using IPA.Config.Stores.Converters;
using System;
using System.Collections.Generic;
using Version = SemVer.Version;
@ -241,4 +244,27 @@ namespace IPA.Utilities
/// <seealso cref="SemverValue"/>
public static implicit operator Version(AlmostVersion av) => av?.SemverValue;
}
/// <summary>
/// A <see cref="ValueConverter{T}"/> for <see cref="AlmostVersion"/>s.
/// </summary>
public sealed class AlmostVersionConverter : ValueConverter<AlmostVersion>
{
/// <summary>
/// Converts a <see cref="Text"/> node into an <see cref="AlmostVersion"/>.
/// </summary>
/// <param name="value">the <see cref="Text"/> node to convert</param>
/// <param name="parent">the owner of the new object</param>
/// <returns></returns>
public override AlmostVersion FromValue(Value value, object parent)
=> new AlmostVersion(Converter<string>.Default.FromValue(value, parent));
/// <summary>
/// Converts an <see cref="AlmostVersion"/> to a <see cref="Text"/> node.
/// </summary>
/// <param name="obj">the <see cref="AlmostVersion"/> to convert</param>
/// <param name="parent">the parent of <paramref name="obj"/></param>
/// <returns>a <see cref="Text"/> node representing <paramref name="obj"/></returns>
public override Value ToValue(AlmostVersion obj, object parent)
=> Value.From(obj.ToString());
}
}

Loading…
Cancel
Save