コード例 #1
0
ファイル: TestDomNodeType.cs プロジェクト: zparr/ATF
        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));
        }
コード例 #2
0
ファイル: Util.cs プロジェクト: trizdreaming/XLE
 /// <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);
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #3
0
 private IEnumerable <DomNode> GetNodesOfType(DomNode rootNode, DomNodeType domNodeType)
 {
     foreach (DomNode domNode in rootNode.Subtree)
     {
         if (domNodeType.IsAssignableFrom(domNode.Type))
         {
             yield return(domNode);
         }
     }
 }
コード例 #4
0
 /// <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);
                     }
                 }
             }
         }
     }
 }
コード例 #5
0
ファイル: TestDomNodeType.cs プロジェクト: sbambach/ATF
        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));
        }
コード例 #6
0
ファイル: Util.cs プロジェクト: ldh9451/XLE
 /// <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;
                 }
             }
         }
     }
 }
コード例 #7
0
        /// <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;
        }
コード例 #8
0
 private IEnumerable<DomNode> GetNodesOfType(DomNode rootNode, DomNodeType domNodeType)
 {
     foreach (DomNode domNode in rootNode.Subtree)
         if (domNodeType.IsAssignableFrom(domNode.Type))
             yield return domNode;
 }