Exemple #1
0
 /// <summary>Initializes a new instance of the <see cref="EnumValues" /> class.</summary>
 /// <param name="enumType">Type of the enum.</param>
 internal EnumValues([NotNull] Type enumType)
 {
     Code.NotNull(enumType, nameof(enumType));
     if (!enumType.IsEnum)
     {
         throw CodeExceptions.Argument(nameof(enumType), $"The {nameof(enumType)} ({enumType}) arg should be a enum type.");
     }
     EnumType      = enumType;
     _values       = GetValues(enumType);
     _valuesByName = _values
                     .ToDictionary(
         f => f.Name,
         StringComparer.InvariantCulture,
         DictionaryDuplicate.FirstWins);
     _valuesByNameIgnoreCase = _values
                               .ToDictionary(
         f => f.Name,
         StringComparer.InvariantCultureIgnoreCase,
         DictionaryDuplicate.FirstWins);
     _valuesByValue = _values
                      .ToDictionary(
         f => f.Value,
         DictionaryDuplicate.FirstWins);
     _valuesByDisplayName = _values
                            .Where(f => f.DisplayName != null)
                            .ToDictionary(
         f => f.DisplayName,
         StringComparer.InvariantCulture,
         DictionaryDuplicate.FirstWins);
 }
Exemple #2
0
 private static void AssertUsage()
 {
     if (!_isEnum && !_isNullableEnum)
     {
         throw CodeExceptions.Argument(
                   typeof(TEnum).Name,
                   $"The {typeof(TEnum).Name} type is not enum type");
     }
 }
Exemple #3
0
 public static void AssertArgument(
     bool condition,
     [NotNull, InvokerParameterName] string argName,
     [NotNull] string message)
 {
     if (!condition)
     {
         throw CodeExceptions.Argument(argName, message);
     }
 }
 public static void AssertArgument(
     [DoesNotReturnIf(false)] bool condition,
     [InvokerParameterName] string argName,
     string message)
 {
     if (!condition)
     {
         throw CodeExceptions.Argument(argName, message);
     }
 }
Exemple #5
0
 public static void AssertArgument(
     bool condition,
     [NotNull, InvokerParameterName] string argName,
     [NotNull] string messageFormat,
     [CanBeNull] params object[] args)
 {
     if (!condition)
     {
         throw CodeExceptions.Argument(argName, messageFormat, args);
     }
 }