internal override bool Compare(object sourceValue, object targetValue, ValueComparisonMethod method) { var realSourceValue = Convert.ToInt32(sourceValue); var realTargetValue = Convert.ToInt32(targetValue); switch (method) { case ValueComparisonMethod.Equal: return(realSourceValue == realTargetValue); case ValueComparisonMethod.Greater: return(realSourceValue > realTargetValue); case ValueComparisonMethod.Less: return(realSourceValue < realTargetValue); case ValueComparisonMethod.GreaterEqual: return(realSourceValue >= realTargetValue); case ValueComparisonMethod.LessEqual: return(realSourceValue <= realTargetValue); case ValueComparisonMethod.Mask: return((realSourceValue & realTargetValue) == realTargetValue); default: return(false); } }
internal virtual bool TryCompare(object sourceValue, object targetValue, ValueComparisonMethod method, out bool result) { if (!IsValidInput(sourceValue, targetValue, method)) { result = false; return(false); } result = Compare(sourceValue, targetValue, method); return(true); }
internal override bool Compare(object sourceValue, object targetValue, ValueComparisonMethod method) { switch (method) { case ValueComparisonMethod.Equal: return(sourceValue.Equals(targetValue)); default: return(false); } }
public static bool TryCompare(object sourceValue, object targetValue, ValueComparisonMethod method, out bool result) { foreach (var comparer in comparers) { if (comparer.TryCompare(sourceValue, targetValue, method, out result)) { return(true); } } result = false; return(false); }
internal override bool Compare(object sourceValue, object targetValue, ValueComparisonMethod method) { var realTargetValue = (bool)targetValue; switch (method) { case ValueComparisonMethod.Equal: return(sourceValue != null ? realTargetValue == (Object)sourceValue : realTargetValue == false); default: return(false); } }
public static IStringComparer Build(ValueComparisonMethod method, StringComparison mode) { switch (method) { case ValueComparisonMethod.OneToOneMatch: return(new StraightComparer(mode)); case ValueComparisonMethod.StartsWith: return(new StartsWithComparer(mode)); case ValueComparisonMethod.Contains: return(new ContainsComparer(mode)); case ValueComparisonMethod.EndsWith: return(new EndsWithComparer(mode)); default: throw new NotImplementedException($"{nameof(ValueComparisonMethod)} value {method.ToString()}"); } }
internal abstract bool Compare(object sourceValue, object targetValue, ValueComparisonMethod method);
internal virtual bool IsValidMethod(ValueComparisonMethod method) { return(true); }
internal virtual bool IsValidInput(object sourceValue, object targetValue, ValueComparisonMethod method) { return(IsValidSource(sourceValue) && IsValidTarget(targetValue) && IsValidMethod(method)); }
internal override bool IsValidMethod(ValueComparisonMethod method) { return(method == ValueComparisonMethod.Equal); }
internal override bool IsValidMethod(ValueComparisonMethod method) { return(method != ValueComparisonMethod.Mask); }
public void TestComparisonPass(object targetValue, object sourceValue, ValueComparisonMethod method, bool expected) { ValueComparisonHelper.TryCompare(targetValue, sourceValue, method, out var actual); Assert.AreEqual(expected, actual); }
public static StraightforwardValueComparer Build(string targetValue, bool ignoreCase, ValueComparisonMethod method) { var mode = ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture; var stringValueComparer = StringValueComparerResolver.Build(method, mode); return(new StraightforwardValueComparer(targetValue, stringValueComparer)); }