Exemplo n.º 1
0
        public override bool Equals(IValue other)
        {
            var otherWrapper = other.GetRawValue() as CLREnumValueWrapper <T>;

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

            return(UnderlyingValue.Equals(otherWrapper.UnderlyingValue));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            var otherBindable = obj as BindableEnum;

            if (otherBindable != null)
            {
                return(UnderlyingValue == otherBindable.UnderlyingValue);
            }

            if (obj is int)
            {
                return(UnderlyingValue.Equals((int)obj));
            }

            return(false);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>
 /// A hash code for the current <see cref="T:System.Object"/>.
 /// </returns>
 public override int GetHashCode()
 {
     return(UnderlyingValue.GetHashCode());
 }
Exemplo n.º 4
0
 public override int GetHashCode()
 {
     return(UnderlyingValue != null ? UnderlyingValue.GetHashCode() : 0);
 }
Exemplo n.º 5
0
        // This method was added in the interest of DRY and is used by MdcSelect & PMdcRadioButtonGroup
        public T ValidateItemList(
            IEnumerable <MdcListElement <T> > items,
            MdcItemValidation appliedItemValidation)
        {
            var componentName = (new Regex("^[a-z,A-Z]*")).Match(GetType().Name).ToString();

            if (items.Count() == 0)
            {
                throw new ArgumentException(componentName + " requires a non-empty Items parameter.");
            }
            if (items.GroupBy(i => i.SelectedValue).Where(g => g.Count() > 1).Count() > 0)
            {
                throw new ArgumentException(componentName + " has multiple enties in the List with the same SelectedValue");
            }

            if (items.Where(i => object.Equals(i.SelectedValue, UnderlyingValue)).Count() == 0)
            {
                switch (appliedItemValidation)
                {
                case MdcItemValidation.DefaultToFirst:
                    var firstOrDefault = items.FirstOrDefault().SelectedValue;
                    return(firstOrDefault);

                case MdcItemValidation.Exception:
                    string itemList = "{ ";
                    string prepend  = "";

                    foreach (var item in items)
                    {
                        itemList += $"{prepend} '{item.SelectedValue}'";
                        prepend   = ",";
                    }

                    itemList += " }";

                    throw new ArgumentException(componentName + $" cannot select item with data value of '{UnderlyingValue?.ToString()}' from {itemList}");

                case MdcItemValidation.NoSelection:
                    return(default);
                }
            }

            return(UnderlyingValue);
        }
Exemplo n.º 6
0
 public override string ToString()
 {
     return(string.Format("({0}, {1})", UnderlyingValue.ToString("N4"), DerivedValue.ToString("N4")));
 }