Beispiel #1
0
        public static IJsonSchemaValidator Create(JsonNode value)
        {
            foreach (var x in value.ArrayItems)
            {
                switch (x.Value.ValueType)
                {
                case JsonValueType.Integer:
                case JsonValueType.Number:
                    return(JsonIntEnumValidator.Create(value.ArrayItems
                                                       .Where(y => y.Value.ValueType == JsonValueType.Integer || y.Value.ValueType == JsonValueType.Number)
                                                       .Select(y => y.GetInt32())
                                                       ));

                case JsonValueType.String:
                    return(JsonStringEnumValidator.Create(value.ArrayItems
                                                          .Where(y => y.Value.ValueType == JsonValueType.String)
                                                          .Select(y => y.GetString())
                                                          ));

                default:
                    break;
                }
            }

            throw new NotImplementedException();
        }
Beispiel #2
0
        public static IJsonSchemaValidator Create(IEnumerable <JsonSchema> composition, EnumSerializationType type)
        {
            foreach (var x in composition)
            {
                if (x.Validator is JsonStringEnumValidator)
                {
                    return(JsonStringEnumValidator.Create(composition
                                                          .Select(y => y.Validator as JsonStringEnumValidator)
                                                          .Where(y => y != null)
                                                          .SelectMany(y => y.Values),
                                                          type
                                                          ));
                }
                if (x.Validator is JsonIntEnumValidator)
                {
                    return(JsonIntEnumValidator.Create(composition
                                                       .Select(y => y.Validator as JsonIntEnumValidator)
                                                       .Where(y => y != null)
                                                       .SelectMany(y => y.Values)
                                                       ));
                }
            }

            throw new NotImplementedException();
        }
Beispiel #3
0
        public static IJsonSchemaValidator Create(ListTreeNode <JsonValue> value)
        {
            foreach (var x in value.ArrayItems())
            {
                if (x.IsInteger() || x.IsFloat())
                {
                    return(JsonIntEnumValidator.Create(value.ArrayItems()
                                                       .Where(y => y.IsInteger() || y.IsFloat())
                                                       .Select(y => y.GetInt32())
                                                       ));
                }
                else if (x.IsString())
                {
                    return(JsonStringEnumValidator.Create(value.ArrayItems()
                                                          .Where(y => y.IsString())
                                                          .Select(y => y.GetString())
                                                          , EnumSerializationType.AsString
                                                          ));
                }
                else
                {
                }
            }

            throw new NotImplementedException();
        }
Beispiel #4
0
        public void IntEnumValidator()
        {
            var c = new JsonSchemaValidationContext("test");

            {
                var v = new JsonIntEnumValidator();
                v.Values = new int[] { 1, 2 };
                Assert.Null(v.Validate(c, 1));
                Assert.NotNull(v.Validate(c, 3));
            }
        }
Beispiel #5
0
        public static IJsonSchemaValidator Create(Type t, EnumSerializationType serializationType, object[] excludes)
        {
            switch (serializationType)
            {
            case EnumSerializationType.AsLowerString:
                return(JsonStringEnumValidator.Create(GetStringValues(t, excludes, x => x.ToLower())));

            case EnumSerializationType.AsInt:
                return(JsonIntEnumValidator.Create(GetIntValues(t, excludes)));

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #6
0
        public static IJsonSchemaValidator Create(object[] values)
        {
            foreach (var x in values)
            {
                if (x is string)
                {
                    return(JsonStringEnumValidator.Create(values.Select(y => (string)y)));
                }
                if (x is int)
                {
                    return(JsonIntEnumValidator.Create(values.Select(y => (int)y)));
                }
            }

            throw new NotImplementedException();
        }