Ejemplo n.º 1
0
 public void TestGetEnclosingClassShortNameByName()
 {
     string[] path = ClassNameParser.GetEnclosingClassShortNames("Com.Microsoft.Tang.Examples.A+B+C");
     Assert.AreEqual(path[0], "A");
     Assert.AreEqual(path[1], "B");
     Assert.AreEqual(path[2], "C");
 }
Ejemplo n.º 2
0
        private INode GetAlreadyBoundNode(Type t)
        {
            string[] outerClassNames = ClassNameParser.GetEnclosingClassShortNames(t);
            string   outerClassName  = outerClassNames[0];
            INode    current         = rootNode.Get(outerClassName);

            if (current == null)
            {
                throw new NameResolutionException(t.FullName, outerClassName);
            }

            for (int i = 1; i < outerClassNames.Length; i++)
            {
                current = current.Get(outerClassNames[i]);
                if (current == null)
                {
                    StringBuilder sb = new StringBuilder(outerClassName);
                    for (int j = 0; j < i; j++)
                    {
                        sb.Append(outerClassNames[j]);
                        if (j != i - 1)
                        {
                            sb.Append(".");
                        }
                    }
                    throw new NameResolutionException(t.FullName, sb.ToString());
                }
            }
            return(current);
        }
Ejemplo n.º 3
0
        //starting from the root, get child for each eclosing class excluding the type itsself
        //all enclosing classes should be already in the hierarchy
        private INode GetParentNode(Type type)
        {
            INode current = rootNode;

            string[] enclosingPath = ClassNameParser.GetEnclosingClassShortNames(type);
            for (int i = 0; i < enclosingPath.Length - 1; i++)
            {
                current = current.Get(enclosingPath[i]);
            }
            return(current);
        }
Ejemplo n.º 4
0
        public INode GetNode(Type type)
        {
            this.RegisterType(type);
            INode current = rootNode;

            string[] enclosingPath = ClassNameParser.GetEnclosingClassShortNames(type);
            for (int i = 0; i < enclosingPath.Length; i++)
            {
                current = current.Get(enclosingPath[i]);
            }
            return(current);
        }
        public INode GetNode(String fullName)
        {
            INode current = rootNode;

            string[] enclosingPath = ClassNameParser.GetEnclosingClassShortNames(fullName);
            for (int i = 0; i < enclosingPath.Length; i++)
            {
                current = current.Get(enclosingPath[i]);
                if (current == null)
                {
                    throw new NameResolutionException(fullName, enclosingPath[i]);
                }
            }

            return(current);
        }
Ejemplo n.º 6
0
        public void TestGetEnclosingClassShortNameByType()
        {
            var  asm     = Assembly.Load(@"Com.Microsoft.Tang.Examples");
            Type seconds = asm.GetType(@"Com.Microsoft.Tang.Examples.Timer+Seconds");
            Type B2      = asm.GetType(@"Com.Microsoft.Tang.Examples.B+B1+B2");
            Type timer   = typeof(Com.Microsoft.Tang.Examples.Timer);

            string[] pathSeconds = ClassNameParser.GetEnclosingClassShortNames(seconds);
            Assert.AreEqual(pathSeconds[0], "Timer");
            Assert.AreEqual(pathSeconds[1], "Seconds");

            string[] pathB2 = ClassNameParser.GetEnclosingClassShortNames(B2);
            Assert.AreEqual(pathB2[0], "B");
            Assert.AreEqual(pathB2[1], "B1");
            Assert.AreEqual(pathB2[2], "B2");

            string[] pathTime = ClassNameParser.GetEnclosingClassShortNames(timer);
            Assert.AreEqual(pathTime[0], "Timer");
        }