예제 #1
0
        public override InstanceMemento[] GetChildrenArray(string key)
        {
            XmlNode childrenNode = _element[key];

            if (childrenNode == null)
            {
                return(null);
            }

            var list    = new ArrayList();
            var element = (XmlElement)childrenNode.FirstChild;

            while (element != null)
            {
                if (element.NodeType == XmlNodeType.Element)
                {
                    InstanceMemento childMemento = new XmlAttributeInstanceMemento(element);
                    list.Add(childMemento);
                }

                element = (XmlElement)element.NextSibling;
            }

            return((InstanceMemento[])list.ToArray(typeof(InstanceMemento)));
        }
        public void Read_in_a_dictionary_type_from_an_attribute_normalized_memento()
        {
            string xml =
                @"
<root>
    <dictionary>
        <Pair Key='color' Value='red'/>
        <Pair Key='state' Value='texas'/>
        <Pair Key='direction' Value='north'/>
    </dictionary>
</root>
";

            XmlElement element = DataMother.BuildDocument(xml).DocumentElement;
            element.SetAttribute("PluggedType", typeof (ClassWithDictionary).AssemblyQualifiedName);

            var memento = new XmlAttributeInstanceMemento(element);

            Instance instance = memento.ReadInstance(typeof(ClassWithDictionary));


//            var theObject =
//                (ClassWithDictionary) instance.Build(typeof (ClassWithDictionary), BuildSession.Empty());
//
//
//            theObject.Dictionary["color"].ShouldEqual("red");
//            theObject.Dictionary["state"].ShouldEqual("texas");
//            theObject.Dictionary["direction"].ShouldEqual("north");

            Assert.Fail("NWO");
        }
        public void Read_in_a_class_with_primitive_arrays()
        {
            string xml = @"
<Instance>
    <numbers Values='1,2,3'/>
    <strings Values='1,2,3'/>
</Instance>
";

            XmlElement element = DataMother.BuildDocument(xml).DocumentElement;
            element.SetAttribute("PluggedType", typeof (ClassWithStringAndIntArray).AssemblyQualifiedName);

            var memento = new XmlAttributeInstanceMemento(element);
            var graph = new PluginGraph();
            Instance instance = memento.ReadInstance(typeof (ClassWithStringAndIntArray));

            Assert.Fail("NWO");

//            var theObject = (ClassWithStringAndIntArray) instance.Build(typeof (ClassWithStringAndIntArray),
//                                                                        BuildSession.ForPluginGraph(graph));
//
//            theObject.Numbers.ShouldEqual(new[] {1, 2, 3});
//            theObject.Strings.ShouldEqual(new[] {"1", "2", "3"});
//
//            Debug.WriteLine(theObject.GetType().AssemblyQualifiedName);
        }
        public override InstanceMemento[] GetChildrenArray(string key)
        {
            XmlNode childrenNode = _element[key];
            if (childrenNode == null)
            {
                return null;
            }

            var list = new ArrayList();
            var element = (XmlElement) childrenNode.FirstChild;
            while (element != null)
            {
                if (element.NodeType == XmlNodeType.Element)
                {
                    InstanceMemento childMemento = new XmlAttributeInstanceMemento(element);
                    list.Add(childMemento);
                }

                element = (XmlElement) element.NextSibling;
            }

            return (InstanceMemento[]) list.ToArray(typeof (InstanceMemento));
        }