public override object Deserialize(SerializationContext serCtx, object mapData, DataNode data) { string file = ((DataValue)data).Value; if (file == "") return ""; string basePath = Path.GetDirectoryName (serCtx.BaseFile); return Runtime.FileUtilityService.RelativeToAbsolutePath (basePath, file); }
public override DataNode Serialize(SerializationContext serCtx, object mapData, object value) { if (value == null || ((string)value).Length == 0) return null; string basePath = Path.GetDirectoryName (serCtx.BaseFile); string file = Runtime.FileUtilityService.AbsoluteToRelativePath (basePath, value.ToString ()); return new DataValue (Name, file); }
public override object Deserialize(SerializationContext serCtx, object mdata, DataNode data) { DataCollection items = ((DataItem) data).ItemData; object position; object collectionInstance = handler.CreateCollection (out position, items.Count); Deserialize (serCtx, mdata, items, collectionInstance, position); return collectionInstance; }
internal DataNode Serialize(SerializationContext serCtx, object value) { DataNode data = dataType.Serialize (serCtx, mapData, value); if (data != null) data.Name = SingleName; return data; }
void Deserialize(SerializationContext serCtx, object obj, DataCollection itemData, string baseName) { Hashtable expandedCollections = null; foreach (DataNode value in itemData) { ItemProperty prop = (ItemProperty) properties [baseName + value.Name]; if (prop == null) { if (value is DataItem) Deserialize (serCtx, obj, ((DataItem)value).ItemData, baseName + value.Name + "/"); continue; } if (prop.WriteOnly) continue; try { if (prop.ExpandedCollection) { ICollectionHandler handler = prop.ExpandedCollectionHandler; if (expandedCollections == null) expandedCollections = new Hashtable (); object pos, col; if (!expandedCollections.ContainsKey (prop)) { col = handler.CreateCollection (out pos, -1); } else { pos = expandedCollections [prop]; col = GetPropValue (prop, obj); } handler.AddItem (ref col, ref pos, prop.Deserialize (serCtx, value)); expandedCollections [prop] = pos; SetPropValue (prop, obj, col); } else { if (prop.HasSetter && prop.DataType.CanCreateInstance) SetPropValue (prop, obj, prop.Deserialize (serCtx, value)); else if (prop.DataType.CanReuseInstance) { object pval = GetPropValue (prop, obj); if (pval == null) { if (prop.HasSetter) throw new InvalidOperationException ("The property '" + prop.Name + "' is null and a new instance of '" + prop.PropertyType + "' can't be created."); else throw new InvalidOperationException ("The property '" + prop.Name + "' is null and it does not have a setter."); } prop.Deserialize (serCtx, value, pval); } else { throw new InvalidOperationException ("The property does not have a setter."); } } } catch (Exception ex) { throw new InvalidOperationException ("Could not set property '" + prop.Name + "' in type '" + Name + "'", ex); } } }
internal void Deserialize(SerializationContext serCtx, object obj, DataCollection itemData) { foreach (ItemProperty prop in Properties) if (prop.DefaultValue != null) SetPropValue (prop, obj, prop.DefaultValue); Deserialize (serCtx, obj, itemData, ""); }
public override DataNode Serialize(SerializationContext serCtx, object mapData, object obj) { if (obj.GetType () != ValueType) { DataType subtype = Context.GetConfigurationDataType (obj.GetType ()); DataItem it = (DataItem) subtype.Serialize (serCtx, mapData, obj); it.ItemData.Add (new DataValue ("ctype", subtype.Name)); it.Name = Name; return it; } DataItem item = new DataItem (); item.Name = Name; ICustomDataItem citem = obj as ICustomDataItem; if (citem != null) { ClassTypeHandler handler = new ClassTypeHandler (serCtx, this); item.ItemData = citem.Serialize (handler); } else item.ItemData = Serialize (serCtx, obj); return item; }
public DataSerializer(DataContext ctx, string baseFile) { dataContext = ctx; serializationContext = ctx.CreateSerializationContext (); serializationContext.BaseFile = baseFile; }
public override DataNode Serialize(SerializationContext serCtx, object mapData, object value) { return new DataValue (Name, value.ToString ()); }
public virtual void Deserialize(SerializationContext serCtx, object mapData, DataNode data, object valueInstance) { throw new InvalidOperationException ("Could not create instance for type '" + ValueType + "'"); }
public abstract object Deserialize(SerializationContext serCtx, object mapData, DataNode data);
public abstract DataNode Serialize(SerializationContext serCtx, object mapData, object value);
public override DataNode Serialize(SerializationContext serCtx, object mdata, object collection) { MapData mapData = (mdata != null) ? (MapData) mdata : GetDefaultData (); DataItem item = new DataItem (); item.Name = Name; item.UniqueNames = false; object pos = handler.GetInitialPosition (collection); while (handler.MoveNextItem (collection, ref pos)) { object val = handler.GetCurrentItem (collection, pos); if (val == null) continue; DataNode data = mapData.ItemType.Serialize (serCtx, mapData.ItemMapData, val); data.Name = mapData.ItemName; item.ItemData.Add (data); } return item; }
public override void Deserialize(SerializationContext serCtx, object mdata, DataNode data, object collectionInstance) { DataCollection items = ((DataItem) data).ItemData; object position; handler.ResetCollection (collectionInstance, out position, items.Count); Deserialize (serCtx, mdata, items, collectionInstance, position); }
public override object Deserialize(SerializationContext serCtx, object mapData, DataNode data) { return Enum.Parse (ValueType, ((DataValue)data).Value, false); }
public override object Deserialize(SerializationContext serCtx, object mapData, DataNode data) { return Convert.ChangeType (((DataValue)data).Value, ValueType); }
public object LoadConfigurationData(SerializationContext serCtx, Type type, DataNode data) { DataType dataType = GetConfigurationDataType (type); return dataType.Deserialize (serCtx, null, data); }
public DataSerializer(DataContext ctx) { dataContext = ctx; serializationContext = ctx.CreateSerializationContext (); }
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); }
public override object Deserialize(SerializationContext serCtx, object mapData, DataNode data) { DataItem item = data as DataItem; if (item == null) throw new InvalidOperationException ("Invalid value found for type '" + Name + "'"); DataValue ctype = item ["ctype"] as DataValue; if (ctype != null && ctype.Value != Name) { DataType stype = FindDerivedType (ctype.Value); if (stype != null) return stype.Deserialize (serCtx, mapData, data); else throw new InvalidOperationException ("Type not found: " + ctype.Value); } ConstructorInfo ctor = ValueType.GetConstructor (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null); if (ctor == null) throw new InvalidOperationException ("Default constructor not found for type '" + ValueType + "'"); object obj = ctor.Invoke (null); SetConfigurationItemData (serCtx, obj, item); return obj; }
public void SetConfigurationItemData(SerializationContext serCtx, object obj, DataItem data) { ClassDataType dataType = (ClassDataType) GetConfigurationDataType (obj.GetType ()); dataType.SetConfigurationItemData (serCtx, obj, data); }
public void SetConfigurationItemData(SerializationContext serCtx, object obj, DataItem item) { ICustomDataItem citem = obj as ICustomDataItem; if (citem != null) { ClassTypeHandler handler = new ClassTypeHandler (serCtx, this); citem.Deserialize (handler, item.ItemData); } else Deserialize (serCtx, obj, item.ItemData); }
internal object Deserialize(SerializationContext serCtx, DataNode data) { return dataType.Deserialize (serCtx, mapData, data); }
internal DataCollection Serialize(SerializationContext serCtx, object obj) { DataCollection itemCol = new DataCollection (); foreach (ItemProperty prop in Properties) { if (prop.ReadOnly) continue; object val = GetPropValue (prop, obj); if (val == null) continue; if (val.Equals (prop.DefaultValue)) continue; DataCollection col = itemCol; if (prop.IsNested) col = GetNestedCollection (col, prop.NameList, 0); if (prop.ExpandedCollection) { ICollectionHandler handler = prop.ExpandedCollectionHandler; object pos = handler.GetInitialPosition (val); while (handler.MoveNextItem (val, ref pos)) { object item = handler.GetCurrentItem (val, pos); if (item == null) continue; DataNode data = prop.Serialize (serCtx, item); data.Name = prop.SingleName; col.Add (data); } } else { DataNode data = prop.Serialize (serCtx, val); if (data == null) continue; col.Add (data); } } return itemCol; }
internal void Deserialize(SerializationContext serCtx, DataNode data, object valueInstance) { dataType.Deserialize (serCtx, mapData, data, valueInstance); }
internal ClassTypeHandler(SerializationContext ctx, ClassDataType cdt) { this.ctx = ctx; this.cdt = cdt; }
void Deserialize(SerializationContext serCtx, object mdata, DataCollection items, object collectionInstance, object position) { MapData mapData = (mdata != null) ? (MapData) mdata : GetDefaultData (); foreach (DataNode val in items) { handler.AddItem (ref collectionInstance, ref position, mapData.ItemType.Deserialize (serCtx, mapData.ItemMapData, val)); } handler.FinishCreation (ref collectionInstance, position); }