public void TestIsAssignableFrom() { DomNodeType parent = new DomNodeType("parent"); Assert.True(parent.IsAssignableFrom(parent)); DomNodeType child = new DomNodeType("child"); child.BaseType = parent; Assert.True(parent.IsAssignableFrom(child)); Assert.False(child.IsAssignableFrom(parent)); }
/// <summary> /// Find all the DomNodes of the type that is equal or derived /// from the given type. /// if exact is true then only find DomNode that have exact type. /// </summary> /// <param name="type">DomNodeType</param> /// <param name="exact">if true then only consider exact match, /// otherwise match any type that is equal or derived from the given type</param> /// <returns></returns> public static IEnumerable <DomNode> FindAll(DomNodeType type, bool exact = false) { if (type != null) { IGameDocumentRegistry gameDocumentRegistry = Globals.MEFContainer.GetExportedValue <IGameDocumentRegistry>(); if (gameDocumentRegistry != null) { foreach (IGameDocument doc in gameDocumentRegistry.Documents) { var enumerable = doc.As <IEnumerableContext>(); if (enumerable != null) { foreach (DomNode childNode in enumerable.Items.AsIEnumerable <DomNode>()) { if ((exact && childNode.Type == type) || (!exact && type.IsAssignableFrom(childNode.Type))) { yield return(childNode); } } } } } } }
private IEnumerable <DomNode> GetNodesOfType(DomNode rootNode, DomNodeType domNodeType) { foreach (DomNode domNode in rootNode.Subtree) { if (domNodeType.IsAssignableFrom(domNode.Type)) { yield return(domNode); } } }
/// <summary> /// Find all the DomNodes of the type that is equal or derived /// from the given type. /// if exact is true then only find DomNode that have exact type. /// </summary> /// <param name="type">DomNodeType</param> /// <param name="exact">if true then only consider exact match, /// otherwise match any type that is equal or derived from the given type</param> /// <returns></returns> public static IEnumerable <DomNode> FindAll(DomNodeType type, bool exact = false) { if (type != null) { IGameDocumentRegistry gameDocumentRegistry = Globals.MEFContainer.GetExportedValue <IGameDocumentRegistry>(); if (gameDocumentRegistry != null) { foreach (IGameDocument doc in gameDocumentRegistry.Documents) { DomNode folderNode = doc.RootGameObjectFolder.Cast <DomNode>(); foreach (DomNode childNode in folderNode.Subtree) { if ((exact && childNode.Type == type) || (!exact && type.IsAssignableFrom(childNode.Type))) { yield return(childNode); } } } } } }
/// <summary> /// Find all the DomNodes of the type that is equal or derived /// from the given type. /// if exact is true then only find DomNode that have exact type. /// </summary> /// <param name="type">DomNodeType</param> /// <param name="exact">if true then only consider exact match, /// otherwise match any type that is equal or derived from the given type</param> /// <returns></returns> public static IEnumerable<DomNode> FindAll(DomNodeType type, bool exact = false) { if (type != null) { IGameDocumentRegistry gameDocumentRegistry = Globals.MEFContainer.GetExportedValue<IGameDocumentRegistry>(); if (gameDocumentRegistry != null) { foreach (IGameDocument doc in gameDocumentRegistry.Documents) { DomNode folderNode = doc.RootGameObjectFolder.Cast<DomNode>(); foreach (DomNode childNode in folderNode.Subtree) { if ((exact && childNode.Type == type) || (!exact && type.IsAssignableFrom(childNode.Type))) yield return childNode; } } } } }
/// <summary> /// Gets all node types derived from base type</summary> /// <param name="baseType">Base type</param> /// <remarks>Base type is not returned in the array.</remarks> /// <returns>Enumeration of all node types derived from baseType</returns> public IEnumerable<DomNodeType> GetNodeTypes(DomNodeType baseType) { if (baseType == null) throw new ArgumentNullException("baseType"); foreach (DomNodeType type in m_nodeTypes.Values) if (type != baseType && baseType.IsAssignableFrom(type)) yield return type; }
private IEnumerable<DomNode> GetNodesOfType(DomNode rootNode, DomNodeType domNodeType) { foreach (DomNode domNode in rootNode.Subtree) if (domNodeType.IsAssignableFrom(domNode.Type)) yield return domNode; }