Esempio n. 1
0
 public static void DisposedIf <TDisposable>(
     bool disposed,
     [NotNull] TDisposable thisReference,
     [NotNull] string message)
     where TDisposable : IDisposable
 {
     if (disposed)
     {
         throw CodeExceptions.ObjectDisposed(thisReference.GetType(), message);
     }
 }
Esempio n. 2
0
 public static void InRange(
     int value,
     [NotNull, InvokerParameterName] string argName,
     int fromValue,
     int toValue)
 {
     if (value < fromValue || value > toValue)
     {
         throw CodeExceptions.ArgumentOutOfRange(argName, value, fromValue, toValue);
     }
 }
 public static void AnyStateFlagSet <TEnum>(
     TEnum value, TEnum flags,
     [NotNull] string messageFormat,
     [CanBeNull] params object[] args)
     where TEnum : struct, Enum
 {
     if (!value.IsAnyFlagSet(flags))
     {
         throw CodeExceptions.InvalidOperation(messageFormat, args);
     }
 }
Esempio n. 4
0
 public static void AssertArgument(
     [AssertionCondition(AssertionConditionType.IS_TRUE)] bool condition,
     [NotNull, InvokerParameterName] string argName,
     [NotNull] string messageFormat,
     [CanBeNull] params object[] args)
 {
     if (!condition)
     {
         throw CodeExceptions.Argument(argName, messageFormat, args);
     }
 }
Esempio n. 5
0
 public static void StateFlagUnset <TEnum>(
     TEnum value, TEnum flag,
     [NotNull] string messageFormat,
     [CanBeNull] params object[] args)
     where TEnum : struct, IComparable, IFormattable, IConvertible
 {
     if (!value.IsFlagUnset(flag))
     {
         throw CodeExceptions.InvalidOperation(messageFormat, args);
     }
 }
Esempio n. 6
0
 public static void DisposedIfNull <TResource, TDisposable>(
     [CanBeNull] TResource resource,
     [NotNull] TDisposable thisReference)
     where TResource : class
     where TDisposable : IDisposable
 {
     if (resource == null)
     {
         throw CodeExceptions.ObjectDisposed(thisReference.GetType());
     }
 }
Esempio n. 7
0
 public static void StateFlagUnset <TEnum>(
     TEnum value, TEnum flag,
     string messageFormat,
     params object[]?args)
     where TEnum : struct, Enum
 {
     if (!value.IsFlagUnset(flag))
     {
         throw CodeExceptions.InvalidOperation(messageFormat, args);
     }
 }
Esempio n. 8
0
 public static void ItemNotNull <T>(
     [NotNull, InstantHandle] IEnumerable <T> arg,
     [NotNull, InvokerParameterName] string argName) where T : class
 {
     foreach (var item in arg)
     {
         if (item == null)
         {
             throw CodeExceptions.ArgumentItemNull(argName);
         }
     }
 }
Esempio n. 9
0
 public static void InRange <T>(
     [NotNull] T value,
     [NotNull, InvokerParameterName] string argName,
     [NotNull] T fromValue,
     [NotNull] T toValue)
 {
     // DONTTOUCH: handles the NaN values
     if (!(Operators <T> .GreaterThanOrEqual(value, fromValue) && Operators <T> .LessThanOrEqual(value, toValue)))
     {
         throw CodeExceptions.ArgumentOutOfRange(argName, value, fromValue, toValue);
     }
 }
Esempio n. 10
0
 public static void DisposedIf <TDisposable>(
     bool disposed,
     [NotNull] TDisposable thisReference,
     [NotNull] string messageFormat,
     [CanBeNull] params object[] args)
     where TDisposable : IDisposable
 {
     if (disposed)
     {
         throw CodeExceptions.ObjectDisposed(thisReference.GetType(), messageFormat, args);
     }
 }
Esempio n. 11
0
 public static void InRange(
     double value,
     [NotNull, InvokerParameterName] string argName,
     double fromValue,
     double toValue)
 {
     // DONTTOUCH: handles the NaN values
     if (!(value >= fromValue && value <= toValue))
     {
         throw CodeExceptions.ArgumentOutOfRange(argName, value, fromValue, toValue);
     }
 }
Esempio n. 12
0
 public static void NotNullNorEmpty <T>(
     [CanBeNull] T[] arg,
     [NotNull, InvokerParameterName] string argName)
 {
     if (arg == null)
     {
         throw CodeExceptions.ArgumentNull(argName);
     }
     if (arg.Length == 0)
     {
         throw CodeExceptions.ArgumentEmpty(argName);
     }
 }
Esempio n. 13
0
 public static void NotNullNorEmpty <T>(
     [CanBeNull, InstantHandle] IEnumerable <T> arg,
     [NotNull, InvokerParameterName] string argName)
 {
     if (arg == null)
     {
         throw CodeExceptions.ArgumentNull(argName);
     }
     if (!arg.Any())
     {
         throw CodeExceptions.ArgumentEmpty(argName);
     }
 }
Esempio n. 14
0
 public static void NotNullNorEmpty <T>(
     [AllowNull, SDC.NotNull] T?[]?arg,
     [InvokerParameterName] string argName)
 {
     if (arg == null)
     {
         throw CodeExceptions.ArgumentNull(argName);
     }
     if (arg.Length == 0)
     {
         throw CodeExceptions.ArgumentEmpty(argName);
     }
 }
Esempio n. 15
0
 public static void NotNullNorEmpty <T>(
     [AllowNull, SDC.NotNull, ValidatedNotNull] ICollection <T>?arg,
     [InvokerParameterName] string argName)
 {
     if (arg == null)
     {
         throw CodeExceptions.ArgumentNull(argName);
     }
     if (arg.Count == 0)
     {
         throw CodeExceptions.ArgumentEmpty(argName);
     }
 }
Esempio n. 16
0
 public static void DisposedIfNull <TResource, TDisposable>(
     [CanBeNull] TResource resource,
     [NotNull] TDisposable thisReference,
     [NotNull] string messageFormat,
     [CanBeNull] params object[] args)
     where TResource : class
     where TDisposable : IDisposable
 {
     if (resource == null)
     {
         throw CodeExceptions.ObjectDisposed(thisReference.GetType(), messageFormat, args);
     }
 }
Esempio n. 17
0
 public static void NotNullNorEmpty <T>(
     [AllowNull, SDC.NotNull, InstantHandle, ValidatedNotNull] IEnumerable <T>?arg,
     [InvokerParameterName] string argName)
 {
     if (arg == null)
     {
         throw CodeExceptions.ArgumentNull(argName);
     }
     if (!arg.Any())
     {
         throw CodeExceptions.ArgumentEmpty(argName);
     }
 }
Esempio n. 18
0
        public static void ValidIndexPair(
            int fromIndex,
            [NotNull, InvokerParameterName] string fromIndexName,
            int toIndex,
            [NotNull, InvokerParameterName] string toIndexName,
            int length)
        {
            ValidIndex(fromIndex, fromIndexName, length);

            if (toIndex < fromIndex || toIndex >= length)
            {
                throw CodeExceptions.IndexOutOfRange(toIndexName, toIndex, fromIndex, length);
            }
        }
Esempio n. 19
0
            private static ulong ToUInt64(object value)
            {
                switch (Convert.GetTypeCode(value))
                {
                case TypeCode.Boolean:
                case TypeCode.Char:
                case TypeCode.Byte:
                case TypeCode.UInt16:
                case TypeCode.UInt32:
                case TypeCode.UInt64:
                    return(Convert.ToUInt64(value, CultureInfo.InvariantCulture));

                case TypeCode.SByte:
                case TypeCode.Int16:
                case TypeCode.Int32:
                case TypeCode.Int64:
                    return(unchecked ((ulong)Convert.ToInt64(value, CultureInfo.InvariantCulture)));

                default:
                    throw CodeExceptions.UnexpectedArgumentValue(nameof(value), value);
                }
            }