コード例 #1
0
        public override object ConvertFromStorageType(object value){
            if (!(string.IsNullOrEmpty(value as string)))
            {
                var settings = new XmlReaderSettings{ConformanceLevel = ConformanceLevel.Auto};
                var reader = XmlReader.Create(new StringReader((string) value), settings);
                var serializableDictionary = new SerializableDictionary<string, string>();
                serializableDictionary.ReadXml(reader);
                var schema = new Schema(new DictionaryXmlReader().ReadFromString(serializableDictionary["Schema"].Replace(":","")));
                var commonSchema = Schema.GetCommonSchema();
                commonSchema.CombineWith(schema);
                var helper = new DictionaryHelper();
                var aspects = serializableDictionary["aspects"].Split(',').ToList();

                string aspectFromXml = helper.GetAspectFromXml(aspects, serializableDictionary["DefaultAspect"]);
                var dictionary = new Dictionary(new DictionaryXmlReader().ReadFromString(aspectFromXml), commonSchema);
                foreach (var aspectValue in aspects.Where(s => !string.IsNullOrEmpty(s))){
                    string xml = serializableDictionary[aspectValue];
                    if (!(string.IsNullOrEmpty(xml)))
                        dictionary.AddAspect(aspectValue, new DictionaryXmlReader().ReadFromString(xml));
                }

                return dictionary;

            }
            return null;
        }
コード例 #2
0
        public void Test()
        {
            const string elXml = "<Application><BOModel><Class Name=\"MyClass\" Caption=\"el&amp;caption\"></Class></BOModel></Application>";
            const string xml = "<Application><BOModel><Class Name=\"MyClass\" Caption=\"capt&quot;ion\"></Class></BOModel></Application>";
            var elDict = new Dictionary(new DictionaryXmlReader().ReadFromString(elXml), Schema.GetCommonSchema());
            var dict = new Dictionary(new DictionaryXmlReader().ReadFromString(xml), Schema.GetCommonSchema());
            Dictionary dictionary = dict.Clone();
            dictionary.AddAspect("el", elDict.RootNode);

            var dictionaryHelper = new DictionaryHelper();
            string aspectFromXml = dictionaryHelper.GetAspectFromXml(new List<string> { "el" }, dictionary.RootNode);

            Assert.AreEqual(dict.RootNode.ToXml(), new DictionaryXmlReader().ReadFromString(aspectFromXml).ToXml());
//            Assert.AreEqual(elDict.RootNode.ToXml(), new DictionaryXmlReader().ReadFromString(dictionaryHelper.AspectValues["el"]).ToXml());


        }