Example #1
0
 protected IndexedList <T, TAttribute> IndexedList <TAttribute>
     (Func <T, IEnumerable <TAttribute> > valueFunc, [CallerMemberName] string callerMember = "")
 {
     if (this.Building)
     {
         return(new IndexedList <T, TAttribute>(valueFunc));
     }
     else
     {
         return((IndexedList <T, TAttribute>)IndexedValues.First(v => v.PropertyName == callerMember));
     }
 }
 protected UniqueIndexedValue <T, TAtt1, TAtt2, TAtt3> UniqueIndexedValue <TAtt1, TAtt2, TAtt3>(
     Func <T, CompoundValue <TAtt1, TAtt2, TAtt3> > valueFunc,
     Func <T, bool> shouldIndexPredicate,
     [CallerMemberName] string callerMember = "")
 {
     if (this.Building)
     {
         return(new UniqueIndexedValue <T, TAtt1, TAtt2, TAtt3>(valueFunc, shouldIndexPredicate));
     }
     else
     {
         return((UniqueIndexedValue <T, TAtt1, TAtt2, TAtt3>)IndexedValues.First(v => v.PropertyName == callerMember));
     }
 }
Example #3
0
 protected IndexedValue <T, TAttribute> IndexedValue <TAttribute>(
     Func <T, TAttribute> valueFunc,
     Func <T, bool> shouldIndexPredicate,
     [CallerMemberName] string callerMember = "")
 {
     if (this.Building)
     {
         return(new IndexedValue <T, TAttribute>(valueFunc, shouldIndexPredicate));
     }
     else
     {
         return((IndexedValue <T, TAttribute>)IndexedValues.First(v => v.PropertyName == callerMember));
     }
 }
        /// <summary>
        /// Creates an Indexed Dictionary
        /// </summary>
        /// <param name="capacity">The starting capacity</param>
        /// <param name="comparer">The equality comparer to use for keys</param>
        public IndexedDictionary(int capacity, IEqualityComparer <TKey>?comparer)
        {
            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(capacity));
            }

            Comparer = comparer ?? EqualityComparer <TKey> .Default;

            if (capacity == 0)
            {
                _Buckets = Empty.Array <int>();
                _Entries = Empty.Array <Entry>();
            }
            else
            {
                _Buckets = new int[capacity];
                _Entries = new Entry[capacity];
            }

            Keys   = new IndexedKeys(this);
            Values = new IndexedValues(this);
        }
Example #5
0
        /// <summary>
        /// Determines whether the specified object instance is considered equal to the current instance.
        /// </summary>
        /// <param name="obj">The object to compare with.</param>
        /// <returns>true if the objects are considered equal; otherwise, false.</returns>
        public override bool Equals(object obj)
        {
            // an indexable option cannot store null
            if (obj == null)
            {
                return(false);
            }

            if (obj is IndexableOption <T> option)
            {
                return(Equals(option));
            }
            else
            {
                if (IsIndexed)
                {
                    return(IndexedValues.Equals(obj));
                }
                else
                {
                    return(SingleValue.Equals(obj));
                }
            }
        }
Example #6
0
        /// <summary>
        /// Copia as informações de outra instância.
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public IStatebleItem CopyFrom(IStatebleItem source)
        {
            if (source == null)
            {
                return(this);
            }
            Identifier     = source.Identifier;
            IsConfigured   = source.IsConfigured;
            ReloadSettings = source.ReloadSettings;
            CopyValue      = source.CopyValue;
            Options        = source.Options;
            if ((CheckDigits == null) || (source.CheckDigits == null) || (CheckDigits.Base != source.CheckDigits.Base) || (CheckDigits.Digits != source.CheckDigits.Digits) || (CheckDigits.Limit != source.CheckDigits.Limit) || (CheckDigits.Start != source.CheckDigits.Start))
            {
                CheckDigits = source.CheckDigits;
            }
            if ((Customization == null) || (!Customization.Equals(source.Customization)))
            {
                Customization = source.Customization;
            }
            if ((DefaultValue == null) || (source.DefaultValue == null) || (!String.Equals(DefaultValue.DefaultValue, source.DefaultValue.DefaultValue)))
            {
                DefaultValue = source.DefaultValue;
            }
            if ((IndexedValues == null) || (source.IndexedValues == null) || (!Enumerable.SequenceEqual(IndexedValues.Select(d => d.IndexDescription + "!" + d.IndexValue), source.IndexedValues.Select(d => d.IndexDescription + "!" + d.IndexValue))))
            {
                IndexedValues = source.IndexedValues;
            }
            if ((Label == null) || (source.Label == null) || (!String.Equals(Label.Title, source.Label.Title)) || (!String.Equals(Label.Description, source.Label.Description)))
            {
                Label = source.Label;
            }
            if ((Length == null) || (source.Length == null) || (Math.Abs(Length.MaxValue - source.Length.MaxValue) > 1E-3) || (Math.Abs(Length.MinValue - source.Length.MinValue) > 1E-3))
            {
                Length = source.Length;
            }
            if ((Mask == null) || (source.Mask == null) || (!String.Equals(Mask.Mask, source.Mask.Mask)))
            {
                Mask = source.Mask;
            }
            if (!Object.Equals(Parser, source.Parser))
            {
                Parser = source.Parser;
            }
            if ((Range == null) || (source.Range == null) || (!String.Equals(Range.FromValue, source.Range.FromValue)) || (!String.Equals(Range.ToValue, source.Range.ToValue)))
            {
                Range = source.Range;
            }
            var asEquatable = Validation as IEquatable <IValidator>;

            if ((Validation == null) || (source.Validation == null) || (!String.Equals(Validation.DefaultMessageTemplate, source.Validation.DefaultMessageTemplate)) || (!String.Equals(Validation.FullName, source.Validation.FullName)) || (Validation.IsExclusiveInList != source.Validation.IsExclusiveInList) || (!String.Equals(Validation.ReturnedParameters, source.Validation.ReturnedParameters)) || (asEquatable == null) || (!asEquatable.Equals(source.Validation)))
            {
                Validation = source.Validation;
            }
            if ((ValidChars == null) || (source.ValidChars == null) || (!String.Equals(ValidChars.ValidChars, source.ValidChars.ValidChars)))
            {
                ValidChars = source.ValidChars;
            }
            if ((Values == null) || (source.Values == null) || (!Enumerable.SequenceEqual(Values.Select(v => v.Value), source.Values.Select(v => v.Value))))
            {
                Values = source.Values;
            }
            return(this);
        }
Example #7
0
        /// <summary>
        /// Lê os dados serializados.
        /// </summary>
        /// <param name="reader"></param>
        void System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.MoveToAttribute("uid"))
            {
                Uid = Guid.Parse(reader.ReadContentAsString());
            }
            if (reader.MoveToAttribute("name"))
            {
                Name = reader.ReadContentAsString();
            }
            if (reader.MoveToAttribute("type"))
            {
                Type = (InputValidateType)Enum.Parse(typeof(InputValidateType), reader.ReadContentAsString());
            }
            reader.MoveToElement();
            if (!reader.IsEmptyElement)
            {
                reader.ReadStartElement();
                while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                {
                    if (reader.IsEmptyElement && !reader.HasAttributes)
                    {
                        reader.Skip();
                        continue;
                    }
                    switch (reader.LocalName)
                    {
                    case "CheckDigits":
                        CheckDigits = ReadElement <InputValidateCheckDigits>(reader);
                        break;

                    case "Default":
                        Default = ReadElement <InputValidateDefault>(reader);
                        break;

                    case "Customization":
                        Customization = ReadElement <InputValidateCustomization>(reader);
                        break;

                    case "IndexedValues":
                    {
                        reader.ReadStartElement();
                        while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                        {
                            if (reader.LocalName == "InputValidateIndexedValue")
                            {
                                var value = new InputValidateIndexedValue();
                                ((System.Xml.Serialization.IXmlSerializable)value).ReadXml(reader);
                                IndexedValues.Add(value);
                            }
                            else
                            {
                                reader.Skip();
                            }
                        }
                        reader.ReadEndElement();
                    }
                    break;

                    case "Length":
                        Length = ReadElement <InputValidateLength>(reader);
                        break;

                    case "Mask":
                        Mask = ReadElement <InputValidateMask>(reader);
                        break;

                    case "Range":
                        Range = ReadElement <InputValidateRange>(reader);
                        break;

                    case "ValidChars":
                        ValidChars = ReadElement <InputValidateValidChars>(reader);
                        break;

                    case "Group":
                        Group = ReadElement <InputValidateGroup>(reader);
                        break;

                    case "Values":
                    {
                        reader.ReadStartElement();
                        while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                        {
                            if (reader.LocalName == "InputValidateValue")
                            {
                                var value = new InputValidateValue();
                                ((System.Xml.Serialization.IXmlSerializable)value).ReadXml(reader);
                                Values.Add(value);
                            }
                            else
                            {
                                reader.Skip();
                            }
                        }
                        reader.ReadEndElement();
                    }
                    break;

                    default:
                        reader.Skip();
                        break;
                    }
                }
                reader.ReadEndElement();
            }
        }