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 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 object OnDeserialize(SerializationContext serCtx, DataNode data) { return(dataType.Deserialize(serCtx, mapData, data)); }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { return XmlConvert.ToDateTime (((DataValue)data).Value, XmlDateTimeSerializationMode.Local); }
internal protected override object OnDeserialize(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); }
protected virtual XmlConfigurationWriter GetChildWriter (DataNode data) { return this; }
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 ""; }
public object Deserialize (Type type, DataNode data) { return dataContext.LoadConfigurationData (serializationContext, type, data); }
public void Write (XmlWriter writer, DataNode data) { if (data is DataValue) writer.WriteElementString (data.Name, ((DataValue)data).Value); else if (data is DataItem) { writer.WriteStartElement (data.Name); WriteAttributes (writer, (DataItem) data); WriteChildren (writer, (DataItem) data); writer.WriteEndElement (); } }
internal protected virtual object OnCreateInstance(SerializationContext serCtx, DataNode data) { throw new InvalidOperationException("Could not create instance for type '" + ValueType + "'"); }
int FindData(string name, out DataCollection colec, bool buildTree) { if (list == null) { colec = null; return(-1); } if (name.IndexOf('/') == -1) { for (int n = 0; n < list.Count; n++) { DataNode data = list [n]; if (data.Name == name) { colec = this; return(n); } } colec = this; return(-1); } else { string[] names = name.Split('/'); int pos = -1; colec = this; DataNode data = null; for (int p = 0; p < names.Length; p++) { if (p > 0) { DataItem item = data as DataItem; if (item != null) { colec = item.ItemData; } else if (buildTree) { item = new DataItem(); item.Name = names [p - 1]; colec.Add(item); colec = item.ItemData; } else { colec = null; return(-1); } } pos = -1; for (int n = 0; n < colec.List.Count; n++) { data = colec.List [n]; if (data.Name == names [p]) { pos = n; break; } } } return(pos); } }
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 + "'"); }
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); }
public object Deserialize(SerializationContext serCtx, object mapData, DataNode data) { return(serCtx.Serializer.OnDeserialize(this, serCtx, mapData, data)); }
internal void OnDeserialize(SerializationContext serCtx, DataNode data, object valueInstance) { dataType.Deserialize(serCtx, mapData, data, valueInstance); }
internal protected override object OnDeserialize(SerializationContext serCtx, object mapData, DataNode data) { return(new FilePath(((DataValue)data).Value)); }
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(Convert.ChangeType(((DataValue)data).Value, ValueType)); }
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 object OnDeserialize(SerializationContext serCtx, object mapData, DataNode data) { return(XmlConvert.ToDateTime(((DataValue)data).Value, XmlDateTimeSerializationMode.Local)); }
protected virtual void WriteChild (XmlElement elem, DataNode data) { elem.AppendChild (GetChildWriter (data).Write (elem.OwnerDocument, data)); }
internal protected override object OnDeserialize(SerializationContext serCtx, object mapData, DataNode data) { return(TimeSpan.FromTicks(int.Parse(((DataValue)data).Value))); }
void WriteDataNode (StreamWriter sw, string prefix, DataNode node, ref int id) { string name = node.Name; string newPrefix = prefix.Length > 0 ? prefix + "." + name: name; if (node is DataValue) { DataValue val = (DataValue) node; string value = EncodeString (val.Value); sw.WriteLine ("\t\t" + newPrefix + " = " + value); } else { DataItem it = (DataItem) node; sw.WriteLine ("\t\t" + newPrefix + " = $" + id); newPrefix = "$" + id; id ++; foreach (DataNode cn in it.ItemData) WriteDataNode (sw, newPrefix, cn, ref id); } }
protected override XmlConfigurationWriter GetChildWriter(MonoDevelop.Core.Serialization.DataNode data) { // Don't reuse this serializer for children, since it has solution-specific serialization code return(XmlConfigurationWriter.DefaultWriter); }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { return new FilePath (((DataValue) data).Value); }
public object Deserialize(XmlReader reader, Type type) { DataNode data = XmlConfigurationReader.DefaultReader.Read(reader); return(serializer.Deserialize(type, data)); }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { return String.Equals (((DataValue)data).Value, "true", StringComparison.OrdinalIgnoreCase); }
protected virtual void WriteChild(XmlElement elem, DataNode data) { elem.AppendChild(GetChildWriter(data).Write(elem.OwnerDocument, data)); }
internal object Deserialize(SerializationContext serCtx, object instance, DataNode data) { return(serCtx.Serializer.OnDeserializeProperty(this, serCtx, instance, data)); }
internal protected virtual void OnDeserialize (DataType dataType, SerializationContext serCtx, object mapData, DataNode data, object valueInstance) { dataType.OnDeserialize (serCtx, mapData, data, valueInstance); }
internal void Deserialize(SerializationContext serCtx, object instance, DataNode data, object valueInstance) { serCtx.Serializer.OnDeserializeProperty(this, serCtx, instance, data, valueInstance); }
internal protected virtual object OnDeserializeProperty (ItemProperty prop, SerializationContext serCtx, object instance, DataNode data) { return prop.OnDeserialize (serCtx, data); }
protected virtual void WriteChild(XmlWriter writer, DataNode data) { GetChildWriter(data).Write(writer, data); }
internal protected override void OnDeserialize(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); }
internal protected virtual object OnCreateInstance (DataType dataType, SerializationContext serCtx, DataNode data) { return dataType.OnCreateInstance (serCtx, data); }
protected virtual XmlConfigurationWriter GetChildWriter(DataNode data) { return(this); }
internal protected virtual void OnDeserializeProperty (ItemProperty prop, SerializationContext serCtx, object instance, DataNode data, object valueInstance) { prop.OnDeserialize (serCtx, data, valueInstance); }
public DataNode Read(XmlReader reader) { DataItem item = new DataItem(); item.UniqueNames = false; reader.MoveToContent(); string name = reader.LocalName; item.Name = name; while (reader.MoveToNextAttribute()) { if (reader.LocalName == "xmlns") { continue; } DataNode data = ReadAttribute(reader.LocalName, reader.Value); if (data != null) { DataValue val = data as DataValue; if (val != null) { val.StoreAsAttribute = true; } item.ItemData.Add(data); } } reader.MoveToElement(); if (reader.IsEmptyElement) { reader.Skip(); return(item); } reader.ReadStartElement(); string text = ""; while (reader.NodeType != XmlNodeType.EndElement) { if (reader.NodeType == XmlNodeType.Element) { DataNode data = ReadChild(reader, item); if (data != null) { item.ItemData.Add(data); } } else if (reader.NodeType == XmlNodeType.Text || reader.NodeType == XmlNodeType.Whitespace) { text += reader.Value; reader.Skip(); } else { reader.Skip(); } } reader.ReadEndElement(); if (!item.HasItemData && text != "") { return(new DataValue(name, text)); } return(item); }
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 mapData, DataNode data) { return(Enum.Parse(ValueType, ((DataValue)data).Value, true)); }
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 DataCollection Serialize(SerializationContext serCtx, object obj) { DataCollection itemCol = new DataCollection(); foreach (ItemProperty prop in Properties) { if (prop.ReadOnly || !prop.CanSerialize(serCtx, obj)) { continue; } DataCollection col = itemCol; object val = prop.GetValue(obj); if (val == null) { if (serCtx.IncludeDeletedValues) { if (prop.IsNested) { col = GetNestedCollection(col, prop.NameList, 0, true); } col.Add(new DataDeletedNode(prop.SingleName)); } continue; } var isDefault = val.Equals(prop.DefaultValue); if (isDefault && !serCtx.IsDefaultValueSerializationForced(prop)) { continue; } if (prop.IsNested) { col = GetNestedCollection(col, prop.NameList, 0, isDefault); } 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, obj, item); data.Name = prop.SingleName; col.Add(data); } } else { DataNode data = prop.Serialize(serCtx, obj, val); if (data == null) { if (serCtx.IncludeDeletedValues) { col.Add(new DataDeletedNode(prop.SingleName)); } continue; } data.IsDefaultValue = isDefault; col.Add(data); } } if (obj is IExtendedDataItem) { // Serialize raw data which could not be deserialized DataItem uknData = (DataItem)((IExtendedDataItem)obj).ExtendedProperties ["__raw_data"]; if (uknData != null) { itemCol.Merge(uknData.ItemData); } } return(itemCol); }
public XmlElement Write (XmlDocument doc, DataNode data) { XmlElement elem = doc.CreateElement (data.Name); if (data is DataValue) { elem.InnerText = ((DataValue)data).Value; } else if (data is DataItem) { WriteAttributes (elem, (DataItem) data); WriteChildren (elem, (DataItem) data); } return elem; }
internal protected override object OnCreateInstance(SerializationContext serCtx, 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) { bool isFallbackType; DataType stype = FindDerivedType(ctype.Value, null, out isFallbackType); if (isFallbackType) { // Remove the ctype attribute, to make sure it is not checked again // by the fallback type item.ItemData.Remove(ctype); } if (stype != null) { object sobj = stype.CreateInstance(serCtx, data); // Store the original data type, so it can be serialized back if (isFallbackType && sobj is IExtendedDataItem) { ((IExtendedDataItem)sobj).ExtendedProperties ["__raw_ctype"] = ctype; } return(sobj); } 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 + "'"); } return(ctor.Invoke(null)); }
protected virtual void WriteChild (XmlWriter writer, DataNode data) { GetChildWriter (data).Write (writer, data); }
protected internal override void OnDeserialize(SerializationContext serCtx, object mapData, DataNode data, object obj) { DataItem item = (DataItem)data; ICustomDataItem citem = Context.AttributeProvider.GetCustomDataItem(obj); if (citem != null) { ClassTypeHandler handler = new ClassTypeHandler(serCtx, this); citem.Deserialize(handler, item.ItemData); } else { DeserializeNoCustom(serCtx, obj, item.ItemData); } }
protected internal override object OnDeserialize(SerializationContext serCtx, object mapData, DataNode data) { XmlConfigurationWriter sw = new XmlConfigurationWriter(); XmlDocument doc = new XmlDocument(); return(sw.Write(doc, data)); }
internal object OnDeserialize (SerializationContext serCtx, DataNode data) { return dataType.Deserialize (serCtx, mapData, data); }
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 void Deserialize (SerializationContext serCtx, object instance, DataNode data, object valueInstance) { serCtx.Serializer.OnDeserializeProperty (this, serCtx, instance, data, valueInstance); }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { return TimeSpan.FromTicks (long.Parse (((DataValue)data).Value, CultureInfo.InvariantCulture)); }
internal void OnDeserialize (SerializationContext serCtx, DataNode data, object valueInstance) { dataType.Deserialize (serCtx, mapData, data, valueInstance); }
internal protected override object OnDeserialize (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); }
internal protected override object OnDeserialize (SerializationContext serCtx, object mapData, DataNode data) { return TimeSpan.FromTicks (int.Parse (((DataValue)data).Value)); }
public object CreateConfigurationData (SerializationContext serCtx, Type type, DataNode data) { DataType dataType = GetConfigurationDataType (type); return dataType.CreateInstance (serCtx, data); }
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 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; } }