예제 #1
0
        public bool OnSet(PropertyInterceptionInfo propertyInterceptionInfo, object oldValue, object newValue)
        {
            if (ComparerUtils.Equals(oldValue, newValue))
            {
                throw new Exception("");
            }

            return(false);
        }
        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);
            }
        }
예제 #3
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));
        }
예제 #4
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());
        }
예제 #5
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);
        }