Skip to content

Commit

Permalink
Added missing methods on DecimalRangeType
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAnsuz committed Mar 8, 2024
1 parent cd3cf79 commit 7e19be1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Amrv.ConfigurableCompany/API/ConfigTypes/DecimalRangeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;

namespace Amrv.ConfigurableCompany.API.ConfigTypes
Expand All @@ -13,6 +14,8 @@ public class DecimalRangeType : CType
private static readonly Type TYPE_CONVERTABLE = typeof(IConvertible);
private static readonly Type TYPE_ITUPLE = typeof(ITuple);
private static readonly Type TYPE_TUPLE_T_T = typeof(Tuple<,>);
private static readonly MethodInfo METHOD_TUPLE = typeof(DecimalRangeType).GetMethod("TupleOfTypes", BindingFlags.Static | BindingFlags.NonPublic);
private static readonly MethodInfo METHOD_VALUE_TUPLE = typeof(DecimalRangeType).GetMethod("ValueTupleOfTypes", BindingFlags.Static | BindingFlags.NonPublic);

public readonly double Min;
public readonly double Max;
Expand Down Expand Up @@ -163,5 +166,25 @@ protected internal override bool Serialize(in object item, out string data)
data = default;
return false;
}

private static object GenericTuple(object a, object b)
{
return METHOD_TUPLE.MakeGenericMethod(a.GetType(), b.GetType()).Invoke(null, [a, b]);
}

private static object GenericValueTuple(object a, object b)
{
return METHOD_VALUE_TUPLE.MakeGenericMethod(a.GetType(), b.GetType()).Invoke(null, [a, b]);
}

private static Tuple<T1, T2> TupleOfTypes<T1, T2>(T1 a, T2 b)
{
return Tuple.Create(a, b);
}

private static ValueTuple<T1, T2> ValueTupleOfTypes<T1, T2>(T1 a, T2 b)
{
return ValueTuple.Create(a, b);
}
}
}

0 comments on commit 7e19be1

Please sign in to comment.