예제 #1
0
        private SerializedValue toSerializedValue(object getValue)
        {
            if (getValue == null)
            {
                return(SerializedValue.NullReference);
            }
            var            type  = getValue.GetType();
            SerializedType sType = getSerializedType(type);

            if (stringSerializer.CanSerialize(getValue, type))
            {
                return(SerializedValue.CreateSimple(sType, stringSerializer.Serialize(getValue)));
            }
            if (type.IsArray)
            {
                return(SerializedValue.CreateArray(sType, ((IEnumerable)getValue).Cast <object>().Select(toSerializedValue).ToArray()));
            }
            if (isList(type))
            {
                return(SerializedValue.CreateArray(sType, ((IEnumerable)getValue).Cast <object>().Select(toSerializedValue).ToArray()));
            }
            if (isDictionary(type))
            {
                return(serializeDictionary(getValue));
            }
            if (type.IsValueType) // struct
            {
                return(SerializedValue.CreateComplex(sType
                                                     , getAllFields(type).Select(f => createAttributeFromField(getValue, f)).ToArray()));
            }
            if (isPO(getValue))
            {
                onVisitPO(getValue);
                return(SerializedValue.CreateReference(sType, getPOIdentifier(getValue)));
            }

            throw new Exception("Cant serialize value of type: " + getValue.GetType() + " value: " + getValue);
        }
예제 #2
0
 private Type deserializeType(SerializedType type)
 {
     //TODO: provide override
     return(Type.GetType(type.Name));
 }
 public static SerializedValue CreateReference(SerializedType serializedType, POIdentifier reference)
 {
     return(new SerializedValue {
         Type = serializedType, ReferenceIdentifier = reference
     });
 }
 public static SerializedValue CreateComplex(SerializedType serializedType, SerializedAttribute[] attributes)
 {
     return(new SerializedValue {
         Type = serializedType, ComplexAttributes = attributes
     });
 }
 public static SerializedValue CreateSimple(SerializedType serializedType, string serializedPrimitive)
 {
     return(new SerializedValue {
         Type = serializedType, SimpleValue = serializedPrimitive
     });
 }
 public static SerializedValue CreateArray(SerializedType serializedType, SerializedValue[] elements)
 {
     return(new SerializedValue {
         Type = serializedType, ArrayElements = elements
     });
 }