public DataNode SaveConfigurationData(SerializationContext serCtx, object obj, Type type) { if (type == null) { type = obj.GetType(); } DataType dataType = GetConfigurationDataType(type); return(dataType.Serialize(serCtx, null, obj)); }
internal protected override DataNode OnSerialize(SerializationContext serCtx, object mapData, object obj) { string ctype = null; if (obj.GetType() != ValueType) { if (obj is IExtendedDataItem) { // This is set by fallback types, to make sure the original type name is serialized back ctype = (string)((IExtendedDataItem)obj).ExtendedProperties ["__raw_ctype"]; } if (ctype == null) { DataType subtype = Context.GetConfigurationDataType(obj.GetType()); DataNode n = subtype.Serialize(serCtx, mapData, obj); DataItem it = n as DataItem; if (it == null) { it = new DataItem(); n.Name = "Value"; it.ItemData.Add(n); } it.ItemData.Add(new DataValue("ctype", subtype.Name)); it.Name = Name; return(it); } } DataItem item = new DataItem(); item.Name = Name; ICustomDataItem citem = Context.AttributeProvider.GetCustomDataItem(obj); if (citem != null) { ClassTypeHandler handler = new ClassTypeHandler(serCtx, this); item.ItemData = citem.Serialize(handler); } else { item.ItemData = Serialize(serCtx, obj); } if (ctype != null) { item.ItemData.Add(new DataValue("ctype", ctype)); } return(item); }
internal DataNode OnSerialize(SerializationContext serCtx, object value) { DataNode data = dataType.Serialize(serCtx, mapData, value); if (data != null) { // Don't write empty collections or empty objects with the SkipEmpty flag if (data is DataItem && (DataType is CollectionDataType || SkipEmpty)) { DataItem di = (DataItem)data; if (!di.HasItemData) { return(null); } if (di.ItemData.Count == 1 && di.ItemData ["ctype"] != null) { return(null); } } data.Name = SingleName; } return(data); }