Exemplo n.º 1
0
        private void ValidateFloat(JsonSchemaModel schema)
        {
            if (schema == null || !this.TestType(schema, JsonSchemaType.Float))
            {
                return;
            }
            this.ValidateNotDisallowed(schema);
            double num1     = Convert.ToDouble(this._reader.Value, (IFormatProvider)CultureInfo.InvariantCulture);
            double?nullable = schema.Maximum;

            if (nullable.HasValue)
            {
                double num2 = num1;
                nullable = schema.Maximum;
                double valueOrDefault1 = nullable.GetValueOrDefault();
                if ((num2 > valueOrDefault1 ? (nullable.HasValue ? 1 : 0) : 0) != 0)
                {
                    this.RaiseError(
                        "Float {0} exceeds maximum value of {1}.".FormatWith((IFormatProvider)CultureInfo.InvariantCulture,
                                                                             (object)JsonConvert.ToString(num1), (object)schema.Maximum), schema);
                }
                if (schema.ExclusiveMaximum)
                {
                    double num3 = num1;
                    nullable = schema.Maximum;
                    double valueOrDefault2 = nullable.GetValueOrDefault();
                    if ((num3 == valueOrDefault2 ? (nullable.HasValue ? 1 : 0) : 0) != 0)
                    {
                        this.RaiseError(
                            "Float {0} equals maximum value of {1} and exclusive maximum is true.".FormatWith(
                                (IFormatProvider)CultureInfo.InvariantCulture, (object)JsonConvert.ToString(num1),
                                (object)schema.Maximum), schema);
                    }
                }
            }

            nullable = schema.Minimum;
            if (nullable.HasValue)
            {
                double num2 = num1;
                nullable = schema.Minimum;
                double valueOrDefault1 = nullable.GetValueOrDefault();
                if ((num2 < valueOrDefault1 ? (nullable.HasValue ? 1 : 0) : 0) != 0)
                {
                    this.RaiseError(
                        "Float {0} is less than minimum value of {1}.".FormatWith((IFormatProvider)CultureInfo.InvariantCulture,
                                                                                  (object)JsonConvert.ToString(num1), (object)schema.Minimum), schema);
                }
                if (schema.ExclusiveMinimum)
                {
                    double num3 = num1;
                    nullable = schema.Minimum;
                    double valueOrDefault2 = nullable.GetValueOrDefault();
                    if ((num3 == valueOrDefault2 ? (nullable.HasValue ? 1 : 0) : 0) != 0)
                    {
                        this.RaiseError(
                            "Float {0} equals minimum value of {1} and exclusive minimum is true.".FormatWith(
                                (IFormatProvider)CultureInfo.InvariantCulture, (object)JsonConvert.ToString(num1),
                                (object)schema.Minimum), schema);
                    }
                }
            }

            nullable = schema.DivisibleBy;
            if (!nullable.HasValue)
            {
                return;
            }
            double dividend = num1;

            nullable = schema.DivisibleBy;
            double valueOrDefault = nullable.GetValueOrDefault();

            if (JsonValidatingReader.IsZero(JsonValidatingReader.FloatingPointRemainder(dividend, valueOrDefault)))
            {
                return;
            }
            this.RaiseError(
                "Float {0} is not evenly divisible by {1}.".FormatWith((IFormatProvider)CultureInfo.InvariantCulture,
                                                                       (object)JsonConvert.ToString(num1), (object)schema.DivisibleBy), schema);
        }
Exemplo n.º 2
0
        private void ValidateInteger(JsonSchemaModel schema)
        {
            if (schema == null || !this.TestType(schema, JsonSchemaType.Integer))
            {
                return;
            }
            this.ValidateNotDisallowed(schema);
            object objA = this._reader.Value;

            if (schema.Maximum.HasValue)
            {
                if (JValue.Compare(JTokenType.Integer, objA, (object)schema.Maximum) > 0)
                {
                    this.RaiseError(
                        "Integer {0} exceeds maximum value of {1}.".FormatWith((IFormatProvider)CultureInfo.InvariantCulture, objA,
                                                                               (object)schema.Maximum), schema);
                }
                if (schema.ExclusiveMaximum && JValue.Compare(JTokenType.Integer, objA, (object)schema.Maximum) == 0)
                {
                    this.RaiseError(
                        "Integer {0} equals maximum value of {1} and exclusive maximum is true.".FormatWith(
                            (IFormatProvider)CultureInfo.InvariantCulture, objA, (object)schema.Maximum), schema);
                }
            }

            double?nullable = schema.Minimum;

            if (nullable.HasValue)
            {
                if (JValue.Compare(JTokenType.Integer, objA, (object)schema.Minimum) < 0)
                {
                    this.RaiseError(
                        "Integer {0} is less than minimum value of {1}.".FormatWith((IFormatProvider)CultureInfo.InvariantCulture,
                                                                                    objA, (object)schema.Minimum), schema);
                }
                if (schema.ExclusiveMinimum && JValue.Compare(JTokenType.Integer, objA, (object)schema.Minimum) == 0)
                {
                    this.RaiseError(
                        "Integer {0} equals minimum value of {1} and exclusive minimum is true.".FormatWith(
                            (IFormatProvider)CultureInfo.InvariantCulture, objA, (object)schema.Minimum), schema);
                }
            }

            nullable = schema.DivisibleBy;
            if (!nullable.HasValue)
            {
                return;
            }
            double int64 = (double)Convert.ToInt64(objA, (IFormatProvider)CultureInfo.InvariantCulture);

            nullable = schema.DivisibleBy;
            double valueOrDefault = nullable.GetValueOrDefault();

            if (JsonValidatingReader.IsZero(int64 % valueOrDefault))
            {
                return;
            }
            this.RaiseError(
                "Integer {0} is not evenly divisible by {1}.".FormatWith((IFormatProvider)CultureInfo.InvariantCulture,
                                                                         (object)JsonConvert.ToString(objA), (object)schema.DivisibleBy), schema);
        }