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;
		}
예제 #3
0
 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);
		}
예제 #5
0
        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 "";
		}
예제 #8
0
		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 ();
			}
		}
예제 #10
0
 internal protected virtual object OnCreateInstance(SerializationContext serCtx, DataNode data)
 {
     throw new InvalidOperationException("Could not create instance for type '" + ValueType + "'");
 }
예제 #11
0
        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);
            }
        }
예제 #12
0
 internal protected abstract object OnDeserialize(SerializationContext serCtx, object mapData, DataNode data);
예제 #13
0
 internal protected virtual void OnDeserialize(SerializationContext serCtx, object mapData, DataNode data, object valueInstance)
 {
     throw new InvalidOperationException("Could not create instance for type '" + ValueType + "'");
 }
예제 #14
0
 public object CreateInstance(SerializationContext serCtx, DataNode data)
 {
     return(serCtx.Serializer.OnCreateInstance(this, serCtx, data));
 }
예제 #15
0
 public void Deserialize(SerializationContext serCtx, object mapData, DataNode data, object valueInstance)
 {
     serCtx.Serializer.OnDeserialize(this, serCtx, mapData, data, valueInstance);
 }
예제 #16
0
 public object Deserialize(SerializationContext serCtx, object mapData, DataNode data)
 {
     return(serCtx.Serializer.OnDeserialize(this, serCtx, mapData, data));
 }
예제 #17
0
 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));
 }
예제 #19
0
        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)));
 }
예제 #25
0
		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);
			}
		}
예제 #26
0
 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);
		}
예제 #28
0
        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);
		}
예제 #30
0
 protected virtual void WriteChild(XmlElement elem, DataNode data)
 {
     elem.AppendChild(GetChildWriter(data).Write(elem.OwnerDocument, data));
 }
예제 #31
0
 internal object Deserialize(SerializationContext serCtx, object instance, DataNode data)
 {
     return(serCtx.Serializer.OnDeserializeProperty(this, serCtx, instance, data));
 }
예제 #32
0
		internal protected virtual void OnDeserialize (DataType dataType, SerializationContext serCtx, object mapData, DataNode data, object valueInstance)
		{
			dataType.OnDeserialize (serCtx, mapData, data, valueInstance);
		}
예제 #33
0
 internal void Deserialize(SerializationContext serCtx, object instance, DataNode data, object valueInstance)
 {
     serCtx.Serializer.OnDeserializeProperty(this, serCtx, instance, data, valueInstance);
 }
예제 #34
0
		internal protected virtual object OnDeserializeProperty (ItemProperty prop, SerializationContext serCtx, object instance, DataNode data)
		{
			return prop.OnDeserialize (serCtx, data);
		}
예제 #35
0
 protected virtual void WriteChild(XmlWriter writer, DataNode data)
 {
     GetChildWriter(data).Write(writer, data);
 }
예제 #36
0
        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);
        }
예제 #37
0
		internal protected virtual object OnCreateInstance (DataType dataType, SerializationContext serCtx, DataNode data)
		{
			return dataType.OnCreateInstance (serCtx, data);
		}
예제 #38
0
 protected virtual XmlConfigurationWriter GetChildWriter(DataNode data)
 {
     return(this);
 }
예제 #39
0
		internal protected virtual void OnDeserializeProperty (ItemProperty prop, SerializationContext serCtx, object instance, DataNode data, object valueInstance)
		{
			prop.OnDeserialize (serCtx, data, valueInstance);
		}
예제 #40
0
        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);
        }
예제 #41
0
		internal protected virtual object OnDeserialize (DataType dataType, SerializationContext serCtx, object mapData, DataNode data)
		{
			return dataType.OnDeserialize (serCtx, mapData, data);
		}
예제 #42
0
 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;
			}
		}
예제 #44
0
        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;
		}
예제 #46
0
        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);
		}
예제 #48
0
        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);
            }
        }
예제 #49
0
        protected internal override object OnDeserialize(SerializationContext serCtx, object mapData, DataNode data)
        {
            XmlConfigurationWriter sw  = new XmlConfigurationWriter();
            XmlDocument            doc = new XmlDocument();

            return(sw.Write(doc, data));
        }
예제 #50
0
		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;
		}
예제 #52
0
		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));
		}
예제 #54
0
		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);
		}
예제 #56
0
		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));
		}
예제 #58
0
		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;
            }
        }