/// <summary> /// 将所提供的字典转换为<see cref="SchemaDefine"/>类型的对象。 /// </summary> /// <param name="dictionary">作为名称/值对存储的属性数据的 <see cref="T:System.Collections.Generic.IDictionary^2"/> 实例。</param> /// <param name="type">所生成对象的类型。</param> /// <param name="serializer"><see cref="System.Web.Script.Serialization.JavaScriptSerializer"/>实例。</param> /// <returns>反序列化的对象。</returns> public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer) { SchemaDefine schemaDefine = new SchemaDefine(); schemaDefine.Name = DictionaryHelper.GetValue(dictionary, "name", string.Empty); schemaDefine.SnapshotTable = DictionaryHelper.GetValue(dictionary, "snapshotTable", string.Empty); schemaDefine.Category = DictionaryHelper.GetValue(dictionary, "category", string.Empty); schemaDefine.SortOrder = DictionaryHelper.GetValue(dictionary, "sortOrder", 0xFFFF); if (dictionary.ContainsKey("properties")) { SchemaPropertyDefineCollection properties = JSONSerializerExecute.Deserialize <SchemaPropertyDefineCollection>(dictionary["properties"]); schemaDefine.Properties.Clear(); schemaDefine.Properties.CopyFrom(properties); } if (dictionary.ContainsKey("tabs")) { SchemaTabDefineColleciton tabs = JSONSerializerExecute.Deserialize <SchemaTabDefineColleciton>(dictionary["Tabs"]); schemaDefine.Tabs.Clear(); schemaDefine.Tabs.CopyFrom(tabs); } return(schemaDefine); }
public void LoadPropertiesDefine() { SchemaPropertyGroupSettings settings = SchemaPropertyGroupSettings.GetConfig(); foreach (SchemaPropertyGroupConfigurationElement group in settings.Groups) { SchemaPropertyDefineCollection propertiesDefine = new SchemaPropertyDefineCollection(group.AllProperties); Console.WriteLine("Group name: {0}", group.Name); propertiesDefine.ForEach(pd => pd.Output(Console.Out, 1)); } }
public void LoadPropertiesDefine() { SchemaPropertyGroupSettings settings = SchemaPropertyGroupSettings.GetConfig(); foreach (SchemaPropertyGroupConfigurationElement group in settings.Groups) { SchemaPropertyDefineCollection propertiesDefine = new SchemaPropertyDefineCollection(group.AllProperties); Console.WriteLine("Group name: {0}", group.Name); propertiesDefine.ForEach(pd => pd.Output(Console.Out, 1)); } }
private string ToXml(SchemaPropertyDefineCollection def) { //System.IO.StringWriter sw = new System.IO.StringWriter(); //new System.Xml.Serialization.XmlSerializer(typeof(SchemaPropertyDefineCollection)).Serialize(sw, def); //return sw.ToString(); var xDoc = new XDocument(); var xRoot = new XElement("properties"); xDoc.Add(xRoot); foreach (SchemaPropertyDefine item in def) { xRoot.Add(ToElement(item)); } return(xDoc.ToString(SaveOptions.OmitDuplicateNamespaces)); }
private SchemaPropertyDefineCollection FromXml(string value) { //System.IO.StringWriter sw = new System.IO.StringWriter(); //new System.Xml.Serialization.XmlSerializer(typeof(SchemaPropertyDefineCollection)).Deserialize(sw, def); //return sw.ToString(); XElement root = XDocument.Parse(value).Element("properties"); if (root == null) { throw new FormatException("未能找到元素的根元素properties"); } SchemaPropertyDefineCollection collection = new SchemaPropertyDefineCollection(); foreach (XElement item in root.Elements("property")) { collection.Add(ToProperty(item)); } return(collection); }