示例#1
0
 /// <summary>
 /// Defines a new value in this type.
 /// </summary>
 /// <param name="value">Value to define.</param>
 protected void AddValue(EnumArgumentValue value)
 {
     _values.Add(value);
     AddToValueNameMap(_valuesByCaseSensitiveName, value);
     AddToValueNameMap(_valuesByCaseInsensitiveName, value);
     AddToValueMap(_valuesByValue, value);
 }
示例#2
0
        /// <summary>
        /// Adds the given value to the provided name map.
        /// </summary>
        /// <param name="map">Map to add to.</param>
        /// <param name="value">The value to add.</param>
        private static void AddToValueNameMap(Dictionary <string, EnumArgumentValue> map, EnumArgumentValue value)
        {
            // We skip disallowed values.
            if (value.Disallowed)
            {
                return;
            }

            // Make sure the long name for the value isn't a duplicate.
            if (map.ContainsKey(value.LongName))
            {
                throw new ArgumentOutOfRangeException(nameof(value), Strings.EnumValueLongNameIsInvalid);
            }

            // If explicitly provided, make sure the short name for the
            // value isn't a duplicate.
            if ((value.ShortName != null) && map.ContainsKey(value.ShortName))
            {
                throw new ArgumentOutOfRangeException(nameof(value), Strings.EnumValueShortNameIsInvalid);
            }

            // Add the long and short name.
            map[value.LongName] = value;
            if (value.ShortName != null)
            {
                map[value.ShortName] = value;
            }
        }
示例#3
0
 private static void AddToValueMap(Dictionary <object, EnumArgumentValue> map, EnumArgumentValue value)
 {
     // We do our best to add each value to the map; but if there
     // are multiple members that share a value, then the first
     // one will "win".  We don't bother trying to maintain a
     // multimap.
     if (!map.ContainsKey(value.Value))
     {
         map.Add(value.Value, value);
     }
 }