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); }