Exemplo n.º 1
0
            public override void Validate(JToken value, JsonValidatorContext context)
            {
                var groupedValues = value.GroupBy(v => v["key"], v => v["value"], JToken.EqualityComparer);

                foreach (var groupedValue in groupedValues)
                {
                    if (groupedValue.Count() > 1)
                    {
                        context.RaiseError($"Duplicate key: {groupedValue.Key.ToString(Formatting.None)}");
                    }
                }
            }
    public override void Validate(JToken value, JsonValidatorContext context)
    {
        if (value.Type != JTokenType.String)
        {
            return;
        }
        var      stringValue = value.ToString();
        DateTime date;

        if (!DateTime.TryParseExact(stringValue, "dd/MM/yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out date))
        {
            context.RaiseError($"Text '{stringValue}' is not a valid date.");
        }
    }
Exemplo n.º 3
0
            public override void Validate(JToken value, JsonValidatorContext context)
            {
                if (value.Type == JTokenType.String)
                {
                    string s = value.ToString();

                    try
                    {
                        JToken.Parse(s);
                    }
                    catch (Exception ex)
                    {
                        context.RaiseError($"String is not JSON: {ex.Message}");
                    }
                }
            }
            public override void Validate(JToken value, JsonValidatorContext context)
            {
                if (value.Type == JTokenType.String)
                {
                    string s = value.ToString();

                    try
                    {
                        // test whether the string is a known culture, e.g. en-US, fr-FR
                        CultureInfo.GetCultureInfo(s);
                    }
                    catch (CultureNotFoundException)
                    {
                        context.RaiseError($"Text '{s}' is not a valid culture name.");
                    }
                }
            }
            public override void Validate(JToken value, JsonValidatorContext context)
            {
                if (value.Type == JTokenType.String)
                {
                    string s = value.ToString();

                    try
                    {
                        // test whether the string is a known culture, e.g. en-US, fr-FR
                        new CultureInfo(s);
                    }
                    catch (CultureNotFoundException)
                    {
                        context.RaiseError($"Text '{s}' is not a valid culture name.");
                    }
                }
            }
            public override void Validate(JToken value, JsonValidatorContext context)
            {
                var groupedValues = value.GroupBy(v => v["key"], v => v["value"], JToken.EqualityComparer);

                foreach (var groupedValue in groupedValues)
                {
                    if (groupedValue.Count() > 1)
                    {
                        context.RaiseError($"Duplicate key: {groupedValue.Key.ToString(Formatting.None)}");
                    }
                }
            }
            public override void Validate(JToken value, JsonValidatorContext context)
            {
                if (value.Type == JTokenType.String)
                {
                    string s = value.ToString();

                    try
                    {
                        JToken.Parse(s);
                    }
                    catch (Exception ex)
                    {
                        context.RaiseError($"String is not JSON: {ex.Message}");
                    }
                }
            }