20 lines
611 B
C#
20 lines
611 B
C#
namespace Bts.BooleanExpressions.Arguments;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
static class ArgumentMatcher {
|
|
public static bool Match(
|
|
IArgument arg1, IArgument arg2, IDictionary<string, object?> env) {
|
|
var lobj = arg1.GetValue(env);
|
|
var robj = arg2.GetValue(env);
|
|
if (DBNull.Value.Equals(lobj) && robj is string) {
|
|
return false;
|
|
}
|
|
if (lobj is string lstr && robj is string rstr) {
|
|
return Regex.IsMatch(lstr, rstr);
|
|
}
|
|
throw new Exception(
|
|
$"Type mismatch, cannot string match {lobj?.GetType()} with {robj?.GetType()}");
|
|
}
|
|
}
|