ImageMagick.Throw.IfTrue C# (CSharp) Метод

IfTrue() публичный статический Метод

public static IfTrue ( string paramName, bool condition, string message ) : void
paramName string
condition bool
message string
Результат void
    public static void IfTrue(string paramName, bool condition, string message, params object[] args)
    {
      if (condition)
        throw new ArgumentException(FormatMessage(message, args), paramName);
    }
  }

Usage Example

Пример #1
0
        private void CheckValue(object value)
        {
            if (value == null)
            {
                return;
            }

            Type type = value.GetType();

            if (DataType == ExifDataType.Ascii)
            {
                Throw.IfFalse(nameof(value), type == typeof(string), "Value should be a string.");
                return;
            }

            if (type.IsArray)
            {
                Throw.IfTrue(nameof(value), !IsArray, "Value should not be an array.");
                type = type.GetElementType();
            }
            else
            {
                Throw.IfTrue(nameof(value), IsArray, "Value should be an array.");
            }

            switch (DataType)
            {
            case ExifDataType.Byte:
                Throw.IfFalse(nameof(value), type == typeof(byte), "Value should be a byte{0}", IsArray ? " array." : ".");
                break;

            case ExifDataType.DoubleFloat:
                Throw.IfFalse(nameof(value), type == typeof(double), "Value should be a double{0}", IsArray ? " array." : ".");
                break;

            case ExifDataType.Long:
                Throw.IfFalse(nameof(value), type == typeof(uint), "Value should be an unsigned int{0}", IsArray ? " array." : ".");
                break;

            case ExifDataType.Rational:
                Throw.IfFalse(nameof(value), type == typeof(Rational), "Value should be a rational{0}", IsArray ? " array." : ".");
                break;

            case ExifDataType.Short:
                Throw.IfFalse(nameof(value), type == typeof(ushort), "Value should be an unsigned short{0}", IsArray ? " array." : ".");
                break;

            case ExifDataType.SignedByte:
                Throw.IfFalse(nameof(value), type == typeof(sbyte), "Value should be a signed byte{0}", IsArray ? " array." : ".");
                break;

            case ExifDataType.SignedLong:
                Throw.IfFalse(nameof(value), type == typeof(int), "Value should be an int{0}", IsArray ? " array." : ".");
                break;

            case ExifDataType.SignedRational:
                Throw.IfFalse(nameof(value), type == typeof(SignedRational), "Value should be a signed rational{0}", IsArray ? " array." : ".");
                break;

            case ExifDataType.SignedShort:
                Throw.IfFalse(nameof(value), type == typeof(short), "Value should be a short{0}", IsArray ? " array." : ".");
                break;

            case ExifDataType.SingleFloat:
                Throw.IfFalse(nameof(value), type == typeof(float), "Value should be a float{0}", IsArray ? " array." : ".");
                break;

            case ExifDataType.Undefined:
                Throw.IfFalse(nameof(value), type == typeof(byte), "Value should be a byte array.");
                break;

            default:
                throw new NotSupportedException();
            }
        }
All Usage Examples Of ImageMagick.Throw::IfTrue