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(); }
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(); }
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)); } Assert.True(c.IsEmpty()); }
public static IJsonSchemaValidator Create(object[] values, EnumSerializationType type) { foreach (var x in values) { if (x is string) { return(JsonStringEnumValidator.Create(values.Select(y => (string)y), type)); } if (x is int) { return(JsonIntEnumValidator.Create(values.Select(y => (int)y))); } } throw new NotImplementedException(); }
public static IJsonSchemaValidator Create(Type t, EnumSerializationType serializationType, object[] excludes) { switch (serializationType) { case EnumSerializationType.AsInt: return(JsonIntEnumValidator.Create(GetIntValues(t, excludes))); case EnumSerializationType.AsString: return(JsonStringEnumValidator.Create(GetStringValues(t, excludes, x => x), serializationType)); case EnumSerializationType.AsLowerString: return(JsonStringEnumValidator.Create(GetStringValues(t, excludes, x => x.ToLower()), serializationType)); case EnumSerializationType.AsUpperString: return(JsonStringEnumValidator.Create(GetStringValues(t, excludes, x => x.ToUpper()), serializationType)); default: throw new NotImplementedException(); } }