/// <summary> /// Create Persistent Schema Elements /// </summary> /// <param name="collection"></param> /// <param name="schemaElements"></param> /// <param name="dataElements"></param> public static void CreatePersistentSchemaElements(this IPropertySetCollection collection, out List <PersistentSchemaElement> schemaElements, out List <PersistentPropertyElement> dataElements) { schemaElements = new List <PersistentSchemaElement>(); dataElements = new List <PersistentPropertyElement>(); foreach (var schema in collection.Schemas.Schemas) { SchemaJsonSerializationVisitor visitor = new SchemaJsonSerializationVisitor(); schema.Value.Accept(visitor); PersistentSchemaElement se = new PersistentSchemaElement { SchemaName = schema.Key, SchemaType = visitor.SchemaType.ToString(), SchemaBody = visitor.JsonValue, SerializationHint = (int)visitor.Hint }; schemaElements.Add(se); } foreach (string k in collection.Keys) { PersistentPropertyElement element = new PersistentPropertyElement { Name = k }; ValueSerializationTarget target = new ValueSerializationTarget(element); collection.Schemas.GetSchema(k).Serializer.Serialize(collection[k], target); dataElements.Add(element); } }
/// <summary> /// Serializes the schema. /// </summary> /// <param name="schema">The schema.</param> /// <param name="schemaType">Type of the schema.</param> /// <param name="schemaBody">The schema body.</param> public void SerializeSchema(IValueSchema <object> schema, out Type schemaType, out string schemaBody) { SchemaJsonSerializationVisitor visitor = new SchemaJsonSerializationVisitor(); schema.Accept(visitor); schemaType = visitor.SchemaType; schemaBody = visitor.JsonValue; }
public void TestSerializeStringSchema() { IValueSchema <string> schema = new StringSchema { AllowNull = true, DefaultValue = "abc", MaxLength = 100, MinLength = 2, PossibleValues = new[] { "abc", "def" } }; SchemaJsonSerializationVisitor visitor = new SchemaJsonSerializationVisitor(); schema.Accept(visitor); Assert.AreEqual(typeof(string), visitor.ValueType); Assert.AreEqual(typeof(StringSchema), visitor.SchemaType); Assert.IsNotNull(visitor.JsonValue); Assert.AreNotEqual(0, visitor.JsonValue.Length); }
public void TestDeserializeIntSchema() { IValueSchema <int?> schema = new IntSchema { AllowNull = false, DefaultValue = 10, MaxValue = 100, MinValue = 2, PossibleValues = new int?[] { 10, 20, 30, 100 } }; SchemaJsonSerializationVisitor visitor = new SchemaJsonSerializationVisitor(); schema.Accept(visitor); IValueSchema <object> vs = JsonSchemaDeserializer.Deserialize(visitor.SchemaType, visitor.JsonValue); Assert.IsNotNull(vs); Assert.AreEqual(typeof(int?), vs.Type); }
public void TestSerializeIntSchema() { IValueSchema <int?> schema = new IntSchema { AllowNull = false, DefaultValue = 10, MaxValue = 100, MinValue = 2, PossibleValues = new int?[] { 10, 20, 30, 100 } }; SchemaJsonSerializationVisitor visitor = new SchemaJsonSerializationVisitor(); schema.Accept(visitor); Assert.AreEqual(typeof(int?), visitor.ValueType); Assert.AreEqual(typeof(IntSchema), visitor.SchemaType); Assert.IsNotNull(visitor.JsonValue); Assert.AreNotEqual(0, visitor.JsonValue.Length); }
public void TestDeserializeStringSchema() { IValueSchema <string> schema = new StringSchema { AllowNull = true, DefaultValue = "abc", MaxLength = 100, MinLength = 2, PossibleValues = new[] { "abc", "def" } }; SchemaJsonSerializationVisitor visitor = new SchemaJsonSerializationVisitor(); schema.Accept(visitor); IValueSchema <object> vs = JsonSchemaDeserializer.Deserialize(visitor.SchemaType, visitor.JsonValue); Assert.IsNotNull(vs); Assert.AreEqual(typeof(string), vs.Type); }