예제 #1
0
        /// <summary>
        /// Serializes the property.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="schema">The schema.</param>
        /// <returns></returns>
        public PropertyElement Serialize(object value, IValueSchema <object> schema)
        {
            PropertyElement element = new PropertyElement();

            if (schema != null)
            {
                Type   stype;
                string sbody;
                SerializeSchema(schema, out stype, out sbody);
                element.Schema = new SchemaElement {
                    SchemaBody = sbody, SchemaType = stype.FullName
                };
            }
            PropertyValue v = SerializeValue(value, schema);

            element.SerializationHint = v.SerializationHint;
            element.ValueType         = v.ValueType;
            element.Value             = v.Value;
            return(element);
        }
예제 #2
0
        public object Deserialize(PropertyElement element)
        {
            object value;

            if (element.Value == null)
            {
                return(null);
            }
            Func <PropertyElement, object> func;

            if (_getMap.TryGetValue(element.SerializationHint, out func))
            {
                value = func.Invoke(element);
            }
            else
            {
                StringReader reader = new StringReader((string)element.Value);
                value = _serializer.Deserialize(reader, ResolveType(element.ValueType));
            }
            return(value);
        }