Browse Source

Added Converters file

4.0.0-beta
Anairkoen Schno 5 years ago
parent
commit
cf129d451c
2 changed files with 39 additions and 0 deletions
  1. +38
    -0
      IPA.Loader/Config/Stores/Converters.cs
  2. +1
    -0
      IPA.Loader/IPA.Loader.csproj

+ 38
- 0
IPA.Loader/Config/Stores/Converters.cs View File

@ -0,0 +1,38 @@
using IPA.Config.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IPA.Config.Stores.Converters
{
/// <summary>
/// Provides utility functions for custom converters.
/// </summary>
public static class Converter
{
/// <summary>
/// Gets the integral value of a <see cref="Value"/>, coercing a <see cref="FloatingPoint"/> if necessary,
/// or <see langword="null"/> if <paramref name="val"/> is not an <see cref="Integer"/> or <see cref="FloatingPoint"/>.
/// </summary>
/// <param name="val">the <see cref="Value"/> to get the integral value of</param>
/// <returns>the integral value of <paramref name="val"/>, or <see langword="null"/></returns>
public static long? IntValue(Value val)
=> val is Integer inte ? inte.Value :
val is FloatingPoint fp ? fp.AsInteger()?.Value :
null;
/// <summary>
/// Gets the floaing point value of a <see cref="Value"/>, coercing an <see cref="Integer"/> if necessary,
/// or <see langword="null"/> if <paramref name="val"/> is not an <see cref="Integer"/> or <see cref="FloatingPoint"/>.
/// </summary>
/// <param name="val">the <see cref="Value"/> to get the floaing point value of</param>
/// <returns>the floaing point value of <paramref name="val"/>, or <see langword="null"/></returns>
public static decimal? FloatValue(Value val)
=> val is FloatingPoint fp ? fp.Value :
val is Integer inte ? inte.AsFloat()?.Value :
null;
}
}

+ 1
- 0
IPA.Loader/IPA.Loader.csproj View File

@ -95,6 +95,7 @@
<Compile Include="Config\IConfigStore.cs" /> <Compile Include="Config\IConfigStore.cs" />
<Compile Include="Config\SelfConfig.cs" /> <Compile Include="Config\SelfConfig.cs" />
<Compile Include="Config\Stores\Attributes.cs" /> <Compile Include="Config\Stores\Attributes.cs" />
<Compile Include="Config\Stores\Converters.cs" />
<Compile Include="Config\Stores\GeneratedStore.cs" /> <Compile Include="Config\Stores\GeneratedStore.cs" />
<Compile Include="Config\Stores\GeneratedStoreCollections.cs" /> <Compile Include="Config\Stores\GeneratedStoreCollections.cs" />
<Compile Include="Config\Stores\ValueConverter.cs" /> <Compile Include="Config\Stores\ValueConverter.cs" />


Loading…
Cancel
Save