コード例 #1
0
        /// <summary>
        /// Invokes the validation on the specified context with the specified parameters
        /// </summary>
        /// <param name="sender">The property that invoked the validation</param>
        /// <param name="context">The Viewmodel context that has to be validated</param>
        /// <param name="propertyInfo">The <see cref="PropertyInfo"/> of the validated property</param>
        /// <param name="value">The value of the property</param>
        /// <returns>Has to return true on validation error otherwise false</returns>
        protected override Task <bool> OnValidateAsync(PropertyInfo sender, IValidatableViewModel context, PropertyInfo propertyInfo, object value)
        {
            // if the value is null, then we should return a validation successfull, so that it is
            // possible to have non mandatory inputs
            if (value == null)
            {
                return(Task.FromResult(false));
            }

            if (this.value != null)
            {
                return(Task.FromResult(!ComparerUtils.GreaterThan(value, this.value)));
            }

            var otherProperty = context.GetType().GetPropertyEx(this.propertyName);

            if (otherProperty == null)
            {
                throw new ArgumentException(string.Format("The property '{0}' was not found on '{1}'.", this.propertyName, context.GetType().FullName));
            }

            // Also same for this value
            var comparisonValue = otherProperty.GetValue(context);

            if (comparisonValue == null)
            {
                return(Task.FromResult(false));
            }

            return(Task.FromResult(!ComparerUtils.GreaterThan(value, comparisonValue)));
        }
コード例 #2
0
        public bool OnSet(PropertyInterceptionInfo propertyInterceptionInfo, object oldValue, object newValue)
        {
            if (ComparerUtils.Equals(oldValue, newValue))
            {
                throw new Exception("");
            }

            return(false);
        }
コード例 #3
0
        private bool EqualsCoordinates(double point1XorY, double point2XorY)
        {
            double p1 = point1XorY;
            double p2 = point2XorY;

            p1 = ComparerUtils.GetCanonicalValues(p1, precision);
            p2 = ComparerUtils.GetCanonicalValues(p2, precision);

            return(p1 == p2);
        }
コード例 #4
0
        public bool Equals(Coordinates other)
        {
            var resultOfNaNCheck = ComparerUtils.IsNaNPointComparer(this, other, EqualsCoordinates);

            if (resultOfNaNCheck.HasValue)
            {
                return(resultOfNaNCheck.Value);
            }

            return(EqualsCoordinates(other));
        }
        public override int GetHashCode(T observation)
        {
            if (EqualityComparer <T> .Default.Equals(observation, default(T)))
            {
                return(0);
            }

            double x = ComparerUtils.GetCanonicalValues(observation.EstimatedValue, ComparerUtils.comparePrecision);

            return(x.GetHashCode());
        }
コード例 #6
0
        public void OnGet(PropertyInterceptionInfo propertyInterceptionInfo, object value)
        {
            if (ComparerUtils.Equals(value, (long)30))
            {
                propertyInterceptionInfo.SetValue(9999);
            }

            if (ComparerUtils.Equals(value, (double)66))
            {
                propertyInterceptionInfo.SetValue(78344.8f);
            }
        }
コード例 #7
0
        public void CreateComparerByProperty()
        {
            var comparer = ComparerUtils.CreateComparerByProperty <TestClass>(x => x.Value);

            Assert.True(comparer.Equals(new TestClass(1), new TestClass(1)));
            Assert.True(comparer.Equals(null, null));

            Assert.False(comparer.Equals(new TestClass(1), new TestClass(2)));
            Assert.False(comparer.Equals(null, new TestClass(2)));
            Assert.False(comparer.Equals(new TestClass(1), null));

            Assert.Equal(comparer.GetHashCode(new TestClass(1)), 1.GetHashCode());
        }
コード例 #8
0
        public override int GetHashCode()
        {
            int    hash = 3;
            double x    = X;
            double y    = Y;

            x = ComparerUtils.GetCanonicalValues(x, precision);
            y = ComparerUtils.GetCanonicalValues(y, precision);

            hash = (hash * 7) + x.GetHashCode();
            hash = (hash * 7) + y.GetHashCode();

            return(hash);
        }
コード例 #9
0
        /// <summary>
        /// Invokes the validation on the specified context with the specified parameters
        /// </summary>
        /// <param name="sender">The property that invoked the validation</param>
        /// <param name="context">The viewmodel context that has to be validated</param>
        /// <param name="propertyInfo">The <see cref="PropertyInfo"/> of the validated property</param>
        /// <param name="value">The value of the property</param>
        /// <returns>Has to return true on validation error otherwise false</returns>
        protected override async Task <bool> OnValidateAsync(PropertyInfo sender, IValidatableViewModel context, PropertyInfo propertyInfo, object value)
        {
            // if the value is null, then we should return a validation successfull, so that it is
            // possible to have non mandatory inputs
            if (value == null)
            {
                return(false);
            }

            var secondProperty = context.GetType().GetPropertyEx(this.otherProperty);

            if (secondProperty == null)
            {
                return(true);
            }

            var secondValue = secondProperty.GetValue(context);

            if (sender == null)
            {
                await context.ValidateAsync(propertyInfo, secondProperty.Name);
            }

            if (value is SecureString && (secondValue is SecureString || secondValue == null))
            {
                var ssa = value as SecureString;
                var ssb = secondValue as SecureString;

                if (ssa.Length == 0 && ssb == null)
                {
                    return(true);
                }

                if (ssa.Length != 0 && ssb == null)
                {
                    return(false);
                }

                return(ssa.IsEqualTo(ssb));
            }

            if (secondValue == null)
            {
                return(false);
            }

            return(!ComparerUtils.Equals(value, secondValue));
        }
コード例 #10
0
        private bool EqualsCoordinates(Coordinates other)
        {
            double x1 = X;
            double y1 = Y;

            double x2 = other.X;
            double y2 = other.Y;

            x1 = ComparerUtils.GetCanonicalValues(x1, precision);
            y1 = ComparerUtils.GetCanonicalValues(y1, precision);

            x2 = ComparerUtils.GetCanonicalValues(x2, precision);
            y2 = ComparerUtils.GetCanonicalValues(y2, precision);

            return(x1 == x2 && y1 == y2);
        }
        private bool EqualsCoordinatesOfObservations(Coordinates firstObservationCoordinates, Coordinates secondObservationCoordinates)
        {
            double x1 = firstObservationCoordinates.X;
            double y1 = firstObservationCoordinates.Y;

            double x2 = secondObservationCoordinates.X;
            double y2 = secondObservationCoordinates.Y;

            x1 = ComparerUtils.GetCanonicalValues(x1, ComparerUtils.comparePrecision);
            y1 = ComparerUtils.GetCanonicalValues(y1, ComparerUtils.comparePrecision);

            x2 = ComparerUtils.GetCanonicalValues(x2, ComparerUtils.comparePrecision);
            y2 = ComparerUtils.GetCanonicalValues(y2, ComparerUtils.comparePrecision);

            return(x1 == x2 && y1 == y2);
        }
コード例 #12
0
        /// <summary>
        /// Determines whether two sequences are equal by comparing the elements by using the default equality comparer for their types
        /// </summary>
        /// <param name="first">An <see cref="IEnumerable"/> to compare to second.</param>
        /// <param name="second">An <see cref="IEnumerable"/> to compare to the first sequence.</param>
        /// <returns>
        /// true if the two source sequences are of equal length and their corresponding
        /// elements are equal according to the default equality comparer for their type;
        /// otherwise, false.
        /// </returns>
        /// <exception cref="ArgumentNullException">first or second is null.</exception>
        public static bool SequenceEqual_(this IEnumerable first, IEnumerable second)
        {
            if (first == null)
            {
                throw new ArgumentNullException(nameof(first));
            }

            if (second == null)
            {
                throw new ArgumentNullException(nameof(second));
            }

            var firstCol = first as ICollection;

            if (firstCol != null)
            {
                var secondCol = second as ICollection;

                if (secondCol != null && firstCol.Count != secondCol.Count)
                {
                    return(false);
                }
            }

            /*
             *  Because we never know what is inside the IEnumerable, we have to assume that they are a colourful mix of any type.
             *  This means that this will be a very ineffective and slow comparisson, because we have to check every element for its type
             *  before we try to compare them.
             */

            var e1 = first.GetEnumerator();
            var e2 = second.GetEnumerator();

            e1.Reset();
            e2.Reset();

            while (e1.MoveNext())
            {
                if (!(e2.MoveNext() && ComparerUtils.Equals(e1.Current, e2.Current)))
                {
                    return(false);
                }
            }

            return(!e2.MoveNext());
        }
        public override bool Equals(T xObservation, T yObservation)
        {
            var baseEqualityCompareResult = DefaulValueEquals(xObservation, yObservation);

            if (baseEqualityCompareResult.HasValue)
            {
                return(baseEqualityCompareResult.Value);
            }

            var resultOfNaNCheck = ComparerUtils.IsNaNPointComparer(xObservation.ObservationPoint, yObservation.ObservationPoint, EqualsCoordinatesOfObservations);

            if (resultOfNaNCheck.HasValue)
            {
                return(resultOfNaNCheck.Value);
            }

            return(EqualsCoordinatesOfObservations(xObservation.ObservationPoint, yObservation.ObservationPoint));
        }
コード例 #14
0
        /// <summary>
        /// Removes the first occurrence of a specific object from the <see cref="IEnumerable"/>
        /// </summary>
        /// <param name="items">The <see cref="IEnumerable"/> that may contain the object to remove</param>
        /// <param name="itemToExcept">The object to remove from the <see cref="IEnumerable"/>. The value can be null for reference types.</param>
        /// <returns>A new instance of the <see cref="IEnumerable"/> without the item specified by <paramref name="itemToExcept"/></returns>
        /// <exception cref="ArgumentNullException"><paramref name="items"/> is null</exception>
        public static IEnumerable Except_(this IEnumerable items, object itemToExcept)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            var result = new List <object>();

            foreach (var item in items)
            {
                if (!ComparerUtils.Equals(item, itemToExcept))
                {
                    result.Add(item);
                }
            }

            return(result);
        }
        public override bool Equals(T xObservation, T yObservation)
        {
            var baseEqualityCompareResult = DefaulValueEquals(xObservation, yObservation);

            if (baseEqualityCompareResult.HasValue)
            {
                return(baseEqualityCompareResult.Value);
            }

            if (double.IsNaN(xObservation.EstimatedValue))
            {
                return(double.IsNaN(yObservation.EstimatedValue));
            }

            double x = ComparerUtils.GetCanonicalValues(xObservation.EstimatedValue, ComparerUtils.comparePrecision);
            double y = ComparerUtils.GetCanonicalValues(yObservation.EstimatedValue, ComparerUtils.comparePrecision);

            return(x == y);
        }
        public override int GetHashCode(T observation)
        {
            if (EqualityComparer <T> .Default.Equals(observation, default(T)))
            {
                return(0);
            }

            int    hash = 3;
            double x    = observation.ObservationPoint.X;
            double y    = observation.ObservationPoint.Y;

            x = ComparerUtils.GetCanonicalValues(x, ComparerUtils.comparePrecision);
            y = ComparerUtils.GetCanonicalValues(y, ComparerUtils.comparePrecision);


            hash = (hash * 7) + x.GetHashCode();
            hash = (hash * 7) + y.GetHashCode();

            return(hash);
        }
コード例 #17
0
        public Int32 CompareTo(AppVersion other, Boolean versionFirst)
        {
            if (AppName != other.AppName)
            {
                throw new ArgumentException("Application names is not equals");
            }

            Int32 versionCompare = ComparerUtils.ToCompare(Version, other.Version, false) ?? 0;

            if (versionFirst && versionCompare != 0)
            {
                return(versionCompare);
            }

            if (Status != App.Status.None && other.Status != App.Status.None)
            {
                return(Status.CompareTo(other.Status));
            }

            return(versionCompare);
        }
 private bool EqualsCoordinatesOfObservations(double point1XorY, double point2XorY)
 {
     return(ComparerUtils.GetCanonicalValues(point1XorY, ComparerUtils.comparePrecision)
            == ComparerUtils.GetCanonicalValues(point2XorY, ComparerUtils.comparePrecision));
 }
コード例 #19
0
 public bool Equals([CanBeNull] IBasicStatsCount other)
 => ComparerUtils.HandleNullEqualityComparison(this, other) ??
 // ReSharper disable once PossibleNullReferenceException
 TrueCount == other.TrueCount && FalseCount == other.FalseCount;