Пример #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        public bool Add(IEnumerable <Regex> keys, Type enumType, IEnumerable <Enum> values, ref Result error)
        {
            object zeroValue = EnumOps.TryGetEnum(enumType, 0, ref error);

            if (zeroValue != null)
            {
                IEnumerator <Enum> enumerator = values.GetEnumerator(); /* throw */
                bool moveNext = true;

                foreach (Regex key in keys)
                {
                    //
                    // NOTE: If we run out of values before keys, zero fill the
                    //       rest.
                    //
                    object value = zeroValue;

                    //
                    // NOTE: Are we able to continue moving through the items?
                    //
                    if (moveNext)
                    {
                        //
                        // NOTE: Move to the next item.  If this fails, there are
                        //       no more items and we cannot move any farther.
                        //
                        if (!enumerator.MoveNext())
                        {
                            moveNext = false;
                        }

                        //
                        // NOTE: Get the value of the current item.
                        //
                        value = enumerator.Current;
                    }

                    //
                    // NOTE: Add this key/value pair to the dictionary.
                    //
                    this.Add(key, (Enum)value); /* throw */
                }

                return(true);
            }

            return(false);
        }
Пример #2
0
        ///////////////////////////////////////////////////////////////////////

        public bool TryGetValue(
            string key,
            Type enumType,
            out object value,
            ref Result error
            )
        {
            Enum enumValue;

            if (this.TryGetValue(key, out enumValue))
            {
                value = EnumOps.TryGetEnum(enumType, enumValue, ref error);

                return(true);
            }
            else
            {
                value = EnumOps.TryGetEnum(enumType, 0, ref error);

                return(false);
            }
        }