public void Store(ISession session, string name,object value,IValueSchema<object> schema) { PropertyElement element=new PropertyElement(); Action<PropertyElement, object> action; if(_setMap.TryGetValue(schema.Type, out action)) { action.Invoke(element,value); } else { if(schema.Serializer!=null) { } else { } } }
/// <summary> /// Compares the array of possible values. /// </summary> /// <param name="other">The other.</param> /// <returns></returns> private bool ComparePossibleValues(IValueSchema <T> other) { if (PossibleValues == null && other.PossibleValues == null) { return(true); } if (PossibleValues == null || other.PossibleValues == null) { return(false); } if (PossibleValues.Count() != other.PossibleValues.Count()) { return(false); } for (int i = 0; i < PossibleValues.Count(); i++) { if (!AreValuesEqual(PossibleValues.ElementAt(i), other.PossibleValues.ElementAt(i))) { return(false); } } return(true); }
/// <summary> /// Try to get the schema /// </summary> /// <param name="name">The name.</param> /// <param name="objSchema">The obj schema.</param> /// <returns></returns> protected abstract bool OnTryGetValue(string name, out IValueSchema <object> objSchema);
/// <summary> /// Create or save the schema /// </summary> /// <param name="name">The name.</param> /// <param name="wrapped">The wrapped.</param> protected abstract void OnSetSchema(string name, IValueSchema <object> wrapped);
/// <summary> /// Sets the schema for a structure property. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name">The name.</param> /// <param name="schema">The schema.</param> public void SetSchema <T>(string name, IValueSchema <T?> schema) where T : struct { IValueSchema <object> wrapped = schema.Wrap(); OnSetSchema(name, wrapped); }
/// <summary> /// Deserializes the specified element. /// </summary> /// <param name="element">The element.</param> /// <param name="schema">The schema.</param> /// <returns></returns> public object Deserialize(PropertyElement element,out IValueSchema<object> schema) { object value; Type schemaType = ResolveType(element.SchemaType); Type valueType = ResolveType(element.TypeOfValue); schema = !string.IsNullOrEmpty(element.SchemaBody) ? JsonSchemaDeserializer.Deserialize(schemaType, element.SchemaBody) : _schemaFactory.Create(valueType).Wrap(); Func<PropertyElement, object> func; if (_getMap.TryGetValue(element.SerializationValueType, out func)) { value = func.Invoke(element); } else { StringReader reader=new StringReader(element.ValString); value = _serializer.Deserialize(reader, valueType); } return value; }
/// <summary> /// Serializes the property. /// </summary> /// <param name="name">The name.</param> /// <param name="value">The value.</param> /// <param name="schema">The schema.</param> /// <returns></returns> public PropertyElement Serialize(string name,object value,IValueSchema<object> schema) { PropertyElement element=new PropertyElement(); JsonSchemaSerializationVisitor visitor=new JsonSchemaSerializationVisitor(); schema.Accept(visitor); Action<PropertyElement, object> action; if(_setMap.TryGetValue(visitor.ValueType,out action)) { action.Invoke(element,value); } else { StringWriter writer=new StringWriter(); _serializer.Serialize(writer,value); element.ValString = writer.ToString(); } element.SchemaType = visitor.SchemaType.FullName; element.TypeOfValue = visitor.ValueType.FullName; element.SchemaBody = visitor.JsonValue; return element; }
/// <summary> /// Try to get the schema /// </summary> /// <param name="name">The name.</param> /// <param name="objSchema">The obj schema.</param> /// <returns></returns> protected override bool OnTryGetValue(string name, out IValueSchema<object> objSchema) { return _schemaStorage.TryGetValue(name, out objSchema); }
public SerializerWrapper(IValueSchema <T> real) { _real = real; }
/// <summary> /// Create or save the schema /// </summary> /// <param name="name">The name.</param> /// <param name="wrapped">The wrapped.</param> protected override void OnSetSchema(string name, IValueSchema <object> wrapped) { _schemaStorage[name] = wrapped; }
/// <summary> /// Wrap a valut type schema /// </summary> /// <typeparam name="T"></typeparam> /// <param name="schema">The schema.</param> public void Visit <T>(IValueSchema <T?> schema) where T : struct { Schema = schema.Wrap(); }
/// <summary> /// Wrap a reference schema /// </summary> /// <typeparam name="T"></typeparam> /// <param name="schema">The schema.</param> public void Visit <T>(IValueSchema <T> schema) where T : class { Schema = schema.Wrap(); }
protected override void AddWithSchema(string name, object value, IValueSchema<object> schema) { _storage.AddWithSchema(name, value, schema); }
protected virtual void AddWithSchema(string name, object value, IValueSchema <object> schema) { Add(name, value); Schemas.SetSchema(name, schema); }
/// <summary> /// Initializes a new instance of the <see cref="SchemaValueTypeWrapper{T}"></see> /// class. /// </summary> /// <param name="real">The real.</param> public SchemaValueTypeWrapper(IValueSchema <T?> real) { _real = real; _serializer = new SerializerWrapper <T?>(_real); }
/// <summary> /// Initializes a new instance of the <see cref="SchemaClassWrapper<T>"/> class. /// </summary> /// <param name="real">The real.</param> public SchemaClassWrapper(IValueSchema <T> real) { _real = real; _serializerWrapper = new SerializerWrapper <T>(_real); }
/// <summary> /// Try to get the schema /// </summary> /// <param name="name">The name.</param> /// <param name="objSchema">The obj schema.</param> /// <returns></returns> protected override bool OnTryGetValue(string name, out IValueSchema <object> objSchema) { return(_schemaStorage.TryGetValue(name, out objSchema)); }
/// <summary> /// Wraps the specified schema. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="schema">The schema.</param> /// <returns></returns> public static IValueSchema <object> Wrap <T>(this IValueSchema <T?> schema) where T : struct { return(new SchemaValueTypeWrapper <T>(schema)); }
/// <summary> /// Create or save the schema /// </summary> /// <param name="name">The name.</param> /// <param name="wrapped">The wrapped.</param> protected override void OnSetSchema(string name, IValueSchema<object> wrapped) { _schemaStorage[name] = wrapped; }