private SerializedValue serializeDictionary(object getValue) { var type = getValue.GetType(); var dict = ((IDictionary)getValue); var keyType = type.GetGenericArguments()[0]; var valueType = type.GetGenericArguments()[1]; return(SerializedValue.CreateComplex(getSerializedType(type), new[] { new SerializedAttribute() { Name = "Keys", Type = getSerializedType(keyType), Value = toSerializedValue(dict.Keys.Cast <object>().ToArray()) }, new SerializedAttribute() { Name = "Values", Type = getSerializedType(valueType), Value = toSerializedValue(dict.Values.Cast <object>().ToArray()) } })); }
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); }