public override string Serialize(Node node, Type typeAttr) { XpcaProxy proxy = new XpcaProxy(node); StringWriter sw = new StringWriter(); using(XmlWriter xmlWriter = new XmlTextWriter(sw)) { xmlWriter.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); xmlWriter.WriteStartElement("root"); foreach (KeyValuePair<string, PropertyInfo> property in proxy.GetPropertiesFor(typeAttr)) { object value = proxy[property.Key]; if (value != null) { xmlWriter.WriteStartElement(property.Key); if(value is IEnumerable<object>) { foreach (object obj in (value as IEnumerable<object>)) { xmlWriter.WriteStartElement("item"); XmlWriteValue(xmlWriter, obj); xmlWriter.WriteEndElement(); } } else { XmlWriteValue(xmlWriter, value); } xmlWriter.WriteEndElement(); } } xmlWriter.WriteEndElement(); } return sw.ToString(); }
public override string Serialize(Node node, Type typeAttr) { XpcaProxy proxy = new XpcaProxy(node); StringWriter sw = new StringWriter(); using(JsonWriter jsonWriter = new JsonTextWriter(sw)) { jsonWriter.Formatting = Newtonsoft.Json.Formatting.None; jsonWriter.WriteStartObject(); foreach (KeyValuePair<string, PropertyInfo> property in proxy.GetPropertiesFor(typeAttr)) { object value = proxy[property.Key]; if (value != null) { jsonWriter.WritePropertyName(property.Key); if(value is IEnumerable<object>) { jsonWriter.WriteStartArray(); foreach (object obj in (value as IEnumerable<object>)) { JsonWriteValue(jsonWriter, obj); } jsonWriter.WriteEndArray(); } else { JsonWriteValue(jsonWriter, value); } } } jsonWriter.WriteEndObject(); } return sw.ToString(); }
public override string Serialize(Node node, Type typeAttr) { XpcaProxy proxy = new XpcaProxy(node); StringWriter sw = new StringWriter(); using (JsonWriter jsonWriter = new JsonTextWriter(sw)) { jsonWriter.Formatting = Newtonsoft.Json.Formatting.None; jsonWriter.WriteStartObject(); foreach (KeyValuePair <string, PropertyInfo> property in proxy.GetPropertiesFor(typeAttr)) { object value = proxy[property.Key]; if (value != null) { jsonWriter.WritePropertyName(property.Key); if (value is IEnumerable <object> ) { jsonWriter.WriteStartArray(); foreach (object obj in (value as IEnumerable <object>)) { JsonWriteValue(jsonWriter, obj); } jsonWriter.WriteEndArray(); } else { JsonWriteValue(jsonWriter, value); } } } jsonWriter.WriteEndObject(); } return(sw.ToString()); }
public override string Serialize(Node node, Type typeAttr) { XpcaProxy proxy = new XpcaProxy(node); StringWriter sw = new StringWriter(); using (XmlWriter xmlWriter = new XmlTextWriter(sw)) { xmlWriter.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); xmlWriter.WriteStartElement("root"); foreach (KeyValuePair <string, PropertyInfo> property in proxy.GetPropertiesFor(typeAttr)) { object value = proxy[property.Key]; if (value != null) { xmlWriter.WriteStartElement(property.Key); if (value is IEnumerable <object> ) { foreach (object obj in (value as IEnumerable <object>)) { xmlWriter.WriteStartElement("item"); XmlWriteValue(xmlWriter, obj); xmlWriter.WriteEndElement(); } } else { XmlWriteValue(xmlWriter, value); } xmlWriter.WriteEndElement(); } } xmlWriter.WriteEndElement(); } return(sw.ToString()); }
private void Save(Node node, JsonTextWriter jsonWriter) { jsonWriter.Formatting = Formatting.Indented; jsonWriter.WritePropertyName(node.FullName); jsonWriter.WriteStartObject(); XpcaProxy proxy = new XpcaProxy(node); foreach (KeyValuePair<string, PropertyInfo> property in proxy.GetPropertiesFor(typeof(ConfigAttribute))) { object value = proxy[property.Key]; if (value != null ) { jsonWriter.WritePropertyName(property.Key); if(value is Node) { jsonWriter.WriteValue("xpca:/" + ((Node)value).FullName); } else { jsonWriter.WriteValue(value.ToString()); } } } jsonWriter.WriteEndObject(); foreach(Node ch in node.Children) { Save(ch, jsonWriter); } }