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

public static IfFalse ( string paramName, bool condition, string message ) : void
paramName string
condition bool
message string
Результат void
Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PerceptualHash"/> class.
        /// </summary>
        /// <param name="perceptualHash">The</param>
        public PerceptualHash(string perceptualHash)
            : this()
        {
            Throw.IfNullOrEmpty(nameof(perceptualHash), perceptualHash);
            Throw.IfFalse(nameof(perceptualHash), perceptualHash.Length == 210, "Invalid hash size.");

            _Channels[PixelChannel.Red]   = new ChannelPerceptualHash(PixelChannel.Red, perceptualHash.Substring(0, 70));
            _Channels[PixelChannel.Green] = new ChannelPerceptualHash(PixelChannel.Green, perceptualHash.Substring(70, 70));
            _Channels[PixelChannel.Blue]  = new ChannelPerceptualHash(PixelChannel.Blue, perceptualHash.Substring(140, 70));
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DoubleMatrix"/> class.
        /// </summary>
        /// <param name="order">The order.</param>
        /// <param name="values">The values to initialize the matrix with.</param>
        protected DoubleMatrix(int order, double[] values)
        {
            Order = order;

            _Values = new double[Order * Order];
            if (values != null)
            {
                Throw.IfFalse(nameof(values), (Order * Order) == values.Length, "Invalid number of values specified");
                Array.Copy(values, _Values, _Values.Length);
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DoubleMatrix"/> class.
        /// </summary>
        /// <param name="order">The order.</param>
        /// <param name="values">The values to initialize the matrix with.</param>
        protected DoubleMatrix(int order, double[] values)
        {
            Throw.IfTrue(nameof(order), order < 1, "Invalid order specified, value has to be at least 1.");

            Order = order;

            _values = new double[Order * Order];
            if (values != null)
            {
                Throw.IfFalse(nameof(values), (Order * Order) == values.Length, "Invalid number of values specified");
                Array.Copy(values, _values, _values.Length);
            }
        }
Пример #4
0
        private void CheckValues <T>(int x, int y, int width, int height, T[] values)
        {
            CheckIndex(x, y);
            Throw.IfNullOrEmpty(nameof(values), values);
            Throw.IfFalse(nameof(values), values.Length % Channels == 0, "Values should have {0} channels.", Channels);

            int length = values.Length;
            int max    = width * height * Channels;

            Throw.IfTrue(nameof(values), length > max, "Too many values specified.");

            length = (x * y * Channels) + length;
            max    = Image.Width * Image.Height * Channels;
            Throw.IfTrue(nameof(values), length > max, "Too many values specified.");
        }
Пример #5
0
        public static Bytes Create(Stream stream, bool allowEmptyStream = false)
        {
            if (allowEmptyStream)
            {
                Throw.IfNull(nameof(stream), stream);
            }
            else
            {
                Throw.IfNullOrEmpty(nameof(stream), stream);
            }

            Throw.IfFalse(nameof(stream), stream.Position == 0, "The position of the stream should be at zero.");

            var data = GetData(stream, out var length);

            return(new Bytes(data, length));
        }
Пример #6
0
        private void Initialize(string value)
        {
            Throw.IfNullOrEmpty(nameof(value), value);

            string[] values = value.Split(' ');
            Throw.IfTrue(nameof(value), values.Length > 2, "Invalid density specified.");

            if (values.Length == 2)
            {
                if (values[1].Equals("cm", StringComparison.OrdinalIgnoreCase))
                {
                    Units = DensityUnit.PixelsPerCentimeter;
                }
                else if (values[1].Equals("inch", StringComparison.OrdinalIgnoreCase))
                {
                    Units = DensityUnit.PixelsPerInch;
                }
                else
                {
                    throw new ArgumentException("Invalid density specified.", nameof(value));
                }
            }

            string[] xyValues = values[0].Split('x');
            Throw.IfTrue(nameof(value), xyValues.Length > 2, "Invalid density specified.");

            double x;

            Throw.IfFalse(nameof(value), double.TryParse(xyValues[0], NumberStyles.Number, CultureInfo.InvariantCulture, out x), "Invalid density specified.");

            double y;

            if (xyValues.Length == 1)
            {
                y = x;
            }
            else
            {
                Throw.IfFalse(nameof(value), double.TryParse(xyValues[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y), "Invalid density specified.");
            }

            X = x;
            Y = y;
        }
Пример #7
0
        private void Initialize(string value)
        {
            string[] values = value.Split('x');
            Throw.IfTrue(nameof(value), values.Length > 2, "Invalid point specified.");

            Throw.IfFalse(nameof(value), double.TryParse(values[0], NumberStyles.Number, CultureInfo.InvariantCulture, out double x), "Invalid point specified.");

            double y;

            if (values.Length == 2)
            {
                Throw.IfFalse(nameof(value), double.TryParse(values[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y), "Invalid point specified.");
            }
            else
            {
                y = x;
            }

            _x = x;
            _y = y;
        }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MagickColor"/> class.
        /// </summary>
        /// <param name="color">The RGBA/CMYK hex string or name of the color (http://www.imagemagick.org/script/color.php).
        /// For example: #F000, #FF000000</param>
#elif Q16 || Q16HDRI
        /// <summary>
        /// Initializes a new instance of the <see cref="MagickColor"/> class.
        /// </summary>
        /// <param name="color">The RGBA/CMYK hex string or name of the color (http://www.imagemagick.org/script/color.php).
        /// For example: #F000, #FF000000, #FFFF000000000000</param>
#else
#error Not implemented!
#endif
        public MagickColor(string color)
        {
            Throw.IfNullOrEmpty(nameof(color), color);

            if (color.Equals("transparent", StringComparison.OrdinalIgnoreCase))
            {
                Initialize(Quantum.Max, Quantum.Max, Quantum.Max, 0);
                return;
            }

            if (color[0] == '#')
            {
                ParseHexColor(color);
                return;
            }

            using (NativeMagickColor instance = new NativeMagickColor())
            {
                Throw.IfFalse(nameof(color), instance.Initialize(color), "Invalid color specified");
                Initialize(instance);
            }
        }
 private void CheckValues <T>(T[] values)
 {
     Throw.IfNullOrEmpty("values", values);
     Throw.IfFalse("values", values.Length % Channels == 0, "Values should have {0} channels.", Channels);
 }
Пример #10
0
 private static void CheckLength(long length)
 {
     Throw.IfFalse(nameof(length), IsSupportedLength(length), $"Streams with a length larger than {int.MaxValue} are not supported, read from file instead.");
 }
Пример #11
0
 internal static void CheckStream(Stream stream)
 {
     Throw.IfFalse(nameof(stream), stream.CanRead, "The stream should be readable.");
     Throw.IfFalse(nameof(stream), stream.CanWrite, "The stream should be writeable.");
     Throw.IfFalse(nameof(stream), stream.CanSeek, "The stream should be seekable.");
 }
Пример #12
0
 private static void CheckLength(long length)
 {
     Throw.IfFalse(nameof(length), IsSupportedLength(length), "Streams with a length larger than 2147483591 are not supported, read from file instead.");
 }
Пример #13
0
 private void CheckIndex(int x, int y)
 {
     Throw.IfFalse("x", x >= 0 && x < _Image.Width, "Invalid X coordinate: {0}.", x);
     Throw.IfFalse("y", y >= 0 && y < _Image.Height, "Invalid Y coordinate: {0}.", y);
 }
Пример #14
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();
            }
        }
Пример #15
0
        public static StreamWrapper CreateForWriting(Stream stream)
        {
            Throw.IfFalse(nameof(stream), stream.CanWrite, "The stream should be writable.");

            return(new StreamWrapper(stream));
        }
Пример #16
0
        public static StreamWrapper CreateForReading(Stream stream)
        {
            Throw.IfFalse(nameof(stream), stream.CanRead, "The stream should be readable.");

            return(new StreamWrapper(stream));
        }
Пример #17
0
 private void CheckIndex(int y)
 {
     Throw.IfFalse("y", y >= 0 && y < Height, "Invalid Y coordinate: {0}.", y);
 }