Bugs (fixed): * FilterStream throws exception when comparing numeric arguments
29 lines
819 B
C#
29 lines
819 B
C#
namespace Bts.BooleanExpressions.Arguments;
|
|
|
|
using bts;
|
|
|
|
using Spark.Core.Collections;
|
|
|
|
static class ArgumentComparer {
|
|
public static int Compare(
|
|
IArgument value1, IArgument value2, IDictionary<string,object?> env) {
|
|
if (value1 is null) {
|
|
throw new ArgumentNullException(nameof(value1));
|
|
}
|
|
if (value2 is null) {
|
|
throw new ArgumentNullException(nameof(value2));
|
|
}
|
|
var cmp1 = value1.Cast<IComparable>();
|
|
var cmp2 = value2.Cast<IComparable>();
|
|
try {
|
|
var v1 = cmp1.GetValue(env);
|
|
var v2 = cmp2.GetValue(env);
|
|
return v1.GetType().IsNumeric() ?
|
|
new NumericComparer().Compare(v1, v2) : v1.CompareTo(v2);
|
|
} catch (Exception ex) {
|
|
Log.Ui.error($"Comparison failed: {ex}");
|
|
throw;
|
|
}
|
|
}
|
|
}
|