Ejemplo n.º 1
0
 public void TestGetEnclosingClassFullNameByName()
 {
     string[] path = ClassNameParser.GetEnclosingClassFullNames("Com.Microsoft.Tang.Examples.A+B+C");
     Assert.AreEqual(path[0], "Com.Microsoft.Tang.Examples.A");
     Assert.AreEqual(path[1], "Com.Microsoft.Tang.Examples.A+B");
     Assert.AreEqual(path[2], "Com.Microsoft.Tang.Examples.A+B+C");
 }
Ejemplo n.º 2
0
        //private string[] GetEnclosingClassShortNames(Type t)
        //{
        //    string[] path = t.FullName.Split('+');

        //    if (path.Length == 1)
        //    {
        //        return new string[1] { t.Name };
        //    }

        //    string[] first = path[0].Split('.');
        //    path[0] = first[first.Length - 1];
        //    return path;
        //}

        //return immidiate enclosing class
        private Type GetIEnclosingClass(Type t)
        {
            //get full name of t, parse it to check if there is any name before it like A+B
            //sample  t = Com.Microsoft.Tang.Examples.B+B1+B2
            //return type of Com.Microsoft.Tang.Examples.B+B1
            string[] path = ClassNameParser.GetEnclosingClassFullNames(t);
            if (path.Length > 1)
            {
                string p = path[path.Length - 2];
                return(GetType(p));
            }
            return(null); // TODO
        }
Ejemplo n.º 3
0
        public void TestGetEnclosingClassFullNameByType()
        {
            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.GetEnclosingClassFullNames(seconds);
            Assert.AreEqual(pathSeconds[0], "Com.Microsoft.Tang.Examples.Timer");
            Assert.AreEqual(pathSeconds[1], "Com.Microsoft.Tang.Examples.Timer+Seconds");

            string[] pathB2 = ClassNameParser.GetEnclosingClassFullNames(B2);
            Assert.AreEqual(pathB2[0], "Com.Microsoft.Tang.Examples.B");
            Assert.AreEqual(pathB2[1], "Com.Microsoft.Tang.Examples.B+B1");
            Assert.AreEqual(pathB2[2], "Com.Microsoft.Tang.Examples.B+B1+B2");

            string[] pathTime = ClassNameParser.GetEnclosingClassFullNames(timer);
            Assert.AreEqual(pathTime[0], "Com.Microsoft.Tang.Examples.Timer");
        }