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"); }
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); }
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); }
public IDocLeaf ChildByName(string childName) { return(PropertyUtils.ByName(this, childName) as IDocLeaf); }
public IEnumerable <string> ChildrenNames() { return(PropertyUtils.NamesByType(GetType())); }