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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
        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()}");
            }
        }
Exemplo n.º 7
0
 internal abstract bool Compare(object sourceValue, object targetValue, ValueComparisonMethod method);
Exemplo n.º 8
0
 internal virtual bool IsValidMethod(ValueComparisonMethod method)
 {
     return(true);
 }
Exemplo n.º 9
0
 internal virtual bool IsValidInput(object sourceValue, object targetValue, ValueComparisonMethod method)
 {
     return(IsValidSource(sourceValue) && IsValidTarget(targetValue) && IsValidMethod(method));
 }
Exemplo n.º 10
0
 internal override bool IsValidMethod(ValueComparisonMethod method)
 {
     return(method == ValueComparisonMethod.Equal);
 }
Exemplo n.º 11
0
 internal override bool IsValidMethod(ValueComparisonMethod method)
 {
     return(method != ValueComparisonMethod.Mask);
 }
Exemplo n.º 12
0
 public void TestComparisonPass(object targetValue, object sourceValue, ValueComparisonMethod method, bool expected)
 {
     ValueComparisonHelper.TryCompare(targetValue, sourceValue, method, out var actual);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 13
0
        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));
        }