/// <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); }
/// <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; } }
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); } }