public DataSerializer (DataContext ctx, string baseFile) { dataContext = ctx; serializationContext = ctx.CreateSerializationContext (); serializationContext.BaseFile = baseFile; serializationContext.Serializer = this; }
internal protected override DataNode OnSerialize (SerializationContext serCtx, object mapData, object value) { FilePath path = value is string ? new FilePath ((string) value) : (FilePath) value; if (path.IsNullOrEmpty) return null; FilePath basePath = Path.GetDirectoryName (serCtx.BaseFile); string file = path.ToRelative (basePath); if (Path.DirectorySeparatorChar != serCtx.DirectorySeparatorChar) file = file.Replace (Path.DirectorySeparatorChar, serCtx.DirectorySeparatorChar); return new DataValue (Name, file); }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { string file = ((DataValue)data).Value; if (!string.IsNullOrEmpty (file)) { if (Path.DirectorySeparatorChar != serCtx.DirectorySeparatorChar) file = file.Replace (serCtx.DirectorySeparatorChar, Path.DirectorySeparatorChar); string basePath = Path.GetDirectoryName (serCtx.BaseFile); file = FileService.RelativeToAbsolutePath (basePath, file); } if (ValueType == typeof (string)) return file; else return (FilePath) file; }
internal protected override DataNode OnSerialize (SerializationContext serCtx, object mapData, object value) { string str = value as string; switch (str) { case "None": str = Nothing; break; case "EmbeddedResource": str = EmbedAsResource; break; case "Content": str = Exclude; break; } return new DataValue (Name, str); }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { string str = ((DataValue)data).Value; switch (str) { case "Nothing": str = BuildAction.None; break; case "EmbedAsResource": str = BuildAction.EmbeddedResource; break; case "FileCopy": case "Exclude": str = BuildAction.Content; break; } return str; }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { var dval = data as DataValue; if (dval != null) { return dval.Value; } //empty strings are serialised as empty elements, which are parsed as empty DataItems, not DataValues var ditem = (DataItem) data; if (ditem.HasItemData) { throw new InvalidOperationException ("Found complex element, expecting primitive"); } return ""; }
internal protected override DataNode OnSerialize (SerializationContext serCtx, object mapData, object value) { return new DataValue (Name, (bool)value ? "true" : "false"); }
internal protected override object OnDeserialize(SerializationContext serCtx, object mapData, DataNode data) { return(XmlConvert.ToDateTime(((DataValue)data).Value, XmlDateTimeSerializationMode.Local)); }
internal protected virtual object OnDeserialize (DataType dataType, SerializationContext serCtx, object mapData, DataNode data) { return dataType.OnDeserialize (serCtx, mapData, data); }
internal protected override object OnDeserialize (SerializationContext serCtx, object mdata, DataNode data) { object col = Activator.CreateInstance (ValueType); Deserialize (serCtx, mdata, data, col); return col; }
internal protected override DataNode OnSerialize (SerializationContext serCtx, object mapData, object value) { return new MSBuildNullableBoolDataValue (Name, (bool?) value); }
internal protected override object OnDeserialize(SerializationContext serCtx, object mapData, DataNode data) { return(TimeSpan.FromTicks(int.Parse(((DataValue)data).Value))); }
internal protected virtual object OnCreateInstance(SerializationContext serCtx, DataNode data) { throw new InvalidOperationException("Could not create instance for type '" + ValueType + "'"); }
internal DataNode Serialize(SerializationContext serCtx, object instance, object value) { return(serCtx.Serializer.OnSerializeProperty(this, serCtx, instance, value)); }
internal protected abstract object OnDeserialize(SerializationContext serCtx, object mapData, DataNode data);
internal protected virtual void OnDeserialize(SerializationContext serCtx, object mapData, DataNode data, object valueInstance) { throw new InvalidOperationException("Could not create instance for type '" + ValueType + "'"); }
internal protected abstract DataNode OnSerialize(SerializationContext serCtx, object mapData, object value);
public object CreateInstance(SerializationContext serCtx, DataNode data) { return(serCtx.Serializer.OnCreateInstance(this, serCtx, data)); }
public void Deserialize(SerializationContext serCtx, object mapData, DataNode data, object valueInstance) { serCtx.Serializer.OnDeserialize(this, serCtx, mapData, data, valueInstance); }
internal protected override DataNode OnSerialize (SerializationContext serCtx, object mapData, object value) { return new DataValue (Name, ((TimeSpan)value).Ticks.ToString (CultureInfo.InvariantCulture)); }
internal bool CanDeserialize(SerializationContext serCtx, object instance) { return(serCtx.Serializer.CanDeserializeProperty(this, serCtx, instance)); }
public object Deserialize(SerializationContext serCtx, object mapData, DataNode data) { return(serCtx.Serializer.OnDeserialize(this, serCtx, mapData, data)); }
internal object Deserialize(SerializationContext serCtx, object instance, DataNode data) { return(serCtx.Serializer.OnDeserializeProperty(this, serCtx, instance, data)); }
internal protected override DataNode OnSerialize(SerializationContext serCtx, object mapData, object value) { return(new DataValue(Name, XmlConvert.ToString((DateTime)value, XmlDateTimeSerializationMode.Local))); }
internal object OnDeserialize(SerializationContext serCtx, DataNode data) { return(dataType.Deserialize(serCtx, mapData, data)); }
internal protected virtual DataNode OnSerialize (DataType dataType, SerializationContext serCtx, object mapData, object value) { return dataType.OnSerialize (serCtx, mapData, value); }
internal void Deserialize(SerializationContext serCtx, object instance, DataNode data, object valueInstance) { serCtx.Serializer.OnDeserializeProperty(this, serCtx, instance, data, valueInstance); }
internal protected override DataNode OnSerialize (SerializationContext serCtx, object mdata, object collection) { MapData mapData = (mdata != null) ? (MapData) mdata : GetDefaultData (); DataItem colItem = new DataItem (); colItem.Name = Name; colItem.UniqueNames = false; IDictionary dict = (IDictionary) collection; foreach (DictionaryEntry e in dict) { DataItem item = new DataItem (); item.Name = mapData.ItemName; item.UniqueNames = true; DataNode key = mapData.KeyType.Serialize (serCtx, null, e.Key); key.Name = mapData.KeyName; DataNode value = mapData.ValueType.Serialize (serCtx, null, e.Value); value.Name = mapData.ValueName; item.ItemData.Add (key); item.ItemData.Add (value); colItem.ItemData.Add (item); } return colItem; }
internal void OnDeserialize(SerializationContext serCtx, DataNode data, object valueInstance) { dataType.Deserialize(serCtx, mapData, data, valueInstance); }
internal protected override void OnDeserialize (SerializationContext serCtx, object mdata, DataNode data, object collectionInstance) { MapData mapData = (mdata != null) ? (MapData) mdata : GetDefaultData (); DataCollection items = ((DataItem) data).ItemData; IDictionary dict = (IDictionary) collectionInstance; foreach (DataItem item in items) { DataNode key = item.ItemData [mapData.KeyName]; if (key == null) continue; DataNode val = item.ItemData [mapData.ValueName]; object keyObj = mapData.KeyType.Deserialize (serCtx, null, key); object valueObj = val != null ? mapData.ValueType.Deserialize (serCtx, null, val) : null; dict [keyObj] = valueObj; } }
internal protected override DataNode OnSerialize (SerializationContext serCtx, object mapData, object value) { string file = value.ToString (); if (Path.DirectorySeparatorChar != serCtx.DirectorySeparatorChar) file = file.Replace (Path.DirectorySeparatorChar, serCtx.DirectorySeparatorChar); return new DataValue (Name, file); }
internal protected override DataNode OnSerialize(SerializationContext serCtx, object mapData, object value) { return(new DataValue(Name, ((TimeSpan)value).Ticks.ToString())); }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { return Convert.ChangeType (((DataValue)data).Value, ValueType); }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { string file = ((DataValue)data).Value; if (!string.IsNullOrEmpty (file)) { if (Path.DirectorySeparatorChar != serCtx.DirectorySeparatorChar) file = file.Replace (serCtx.DirectorySeparatorChar, Path.DirectorySeparatorChar); } return (FilePath) file; }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { return XmlConvert.ToDateTime (((DataValue)data).Value, XmlDateTimeSerializationMode.Local); }
internal protected override DataNode OnSerialize (SerializationContext serCtx, object mapData, object value) { if (value is IConvertible) return new DataValue(Name, ((IConvertible)value).ToString(CultureInfo.InvariantCulture)); return new DataValue (Name, value.ToString ()); }
internal protected override DataNode OnSerialize (SerializationContext serCtx, object mapData, object value) { return new DataValue (Name, ((FilePath) value).ToString ()); }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { return TimeSpan.FromTicks (long.Parse (((DataValue)data).Value, CultureInfo.InvariantCulture)); }
public DataNode Serialize(SerializationContext serCtx, object mapData, object value) { return(serCtx.Serializer.OnSerialize(this, serCtx, mapData, value)); }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { return new FilePath (((DataValue) data).Value); }
internal protected virtual object OnDeserializeProperty (ItemProperty prop, SerializationContext serCtx, object instance, DataNode data) { return prop.OnDeserialize (serCtx, data); }
internal protected override DataNode OnSerialize (SerializationContext serCtx, object mapData, object value) { return new DataValue (Name, XmlConvert.ToString ((DateTime)value, XmlDateTimeSerializationMode.Local)); }
internal protected virtual void OnDeserializeProperty (ItemProperty prop, SerializationContext serCtx, object instance, DataNode data, object valueInstance) { prop.OnDeserialize (serCtx, data, valueInstance); }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { return TimeSpan.FromTicks (int.Parse (((DataValue)data).Value)); }
internal protected virtual bool CanHandleProperty (ItemProperty property, SerializationContext serCtx, object instance) { return true; }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { return String.Equals (((DataValue)data).Value, "true", StringComparison.OrdinalIgnoreCase); }
public DataSerializer (DataContext ctx) { dataContext = ctx; serializationContext = ctx.CreateSerializationContext (); serializationContext.Serializer = this; }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { var d = (DataValue)data; if (string.IsNullOrEmpty (d.Value)) return (bool?) null; return (bool?) String.Equals (d.Value, "true", StringComparison.OrdinalIgnoreCase); }
internal protected override object OnDeserialize(SerializationContext serCtx, object mapData, DataNode data) { return(Convert.ChangeType(((DataValue)data).Value, ValueType)); }