コード例 #1
0
ファイル: TestCoreDocument.cs プロジェクト: MRoc/puremp3
        static void TestDocPropertyUtils()
        {
            TestDocument document = DocNode.Create <TestDocument>();

            string[] names = PropertyUtils.NamesByType(document.GetType());

            UnitTest.Test(names.Length == 3);
            UnitTest.Test(names[0] == "TestList");
            UnitTest.Test(names[1] == "TestBool");
            UnitTest.Test(names[2] == "SubDoc");
        }
コード例 #2
0
ファイル: DocNode.cs プロジェクト: MRoc/puremp3
        protected IDocLeaf CreateChildByName(Type type, string name)
        {
            IDocLeaf child = Activator.CreateInstance(type) as IDocLeaf;

            if (child is IDocNode)
            {
                (child as IDocNode).ResolveChildrenLinks();
            }

            PropertyUtils.SetByName(this, name, child);

            child.ResolveParentLink(this, name);

            return(child);
        }
コード例 #3
0
        private static XmlElement DumpWholeTree(this IDocLeaf leaf, string name, HashSet <object> alreadyDumped, XmlDocument doc)
        {
            bool seemsToBeAReference = alreadyDumped.Contains(leaf);

            XmlElement element = doc.CreateElement("Leaf");

            element.SetAttribute("Class", leaf.GetType().Name);
            element.SetAttribute("Name", name);
            element.SetAttribute("Owner", (!seemsToBeAReference).ToString());

            if (!seemsToBeAReference)
            {
                alreadyDumped.Add(leaf);

                if (leaf is DocBase)
                {
                    string[] names = PropertyUtils.NamesByType(leaf.GetType(), PropertyUtils.IsSupported);

                    foreach (var n in names)
                    {
                        IDocLeaf child = PropertyUtils.ByName(leaf, n) as IDocLeaf;

                        if (child != null)
                        {
                            element.AppendChild(child.DumpWholeTree(n, alreadyDumped, doc));
                        }
                    }
                }
                else if (leaf is IDocNode)
                {
                    foreach (var child in (leaf as IDocNode).Children())
                    {
                        if (child != null)
                        {
                            element.AppendChild(child.DumpWholeTree(child.Name, alreadyDumped, doc));
                        }
                    }
                }
            }

            return(element);
        }
コード例 #4
0
ファイル: DocNode.cs プロジェクト: MRoc/puremp3
 public IDocLeaf ChildByName(string childName)
 {
     return(PropertyUtils.ByName(this, childName) as IDocLeaf);
 }
コード例 #5
0
ファイル: DocNode.cs プロジェクト: MRoc/puremp3
 public IEnumerable <string> ChildrenNames()
 {
     return(PropertyUtils.NamesByType(GetType()));
 }