Beispiel #1
0
        public void TestSuperClassGenerics()//ported from simplTestCases tests.generics.TestSimplGenerics.java
        {
            // public class FlickrSearchResult extends MediaSearchResult<Image>
            ClassDescriptor       c      = ClassDescriptor.GetClassDescriptor(typeof(FlickrSearchResult));
            List <GenericTypeVar> scvars = c.GetSuperClassGenericTypeVars();

            Assert.AreEqual(scvars.Count, 1);
            GenericTypeVar var1 = scvars[0];

            Assert.AreSame(var1.ClassDescriptor, ClassDescriptor.GetClassDescriptor(typeof(Image)));

            // public class MediaSearch<M extends Media, T extends MediaSearchResult<M>> extends Search<T>
            c = ClassDescriptor.GetClassDescriptor(typeof(MediaSearch <,>));
            List <GenericTypeVar> vars = c.GetGenericTypeVars();

            scvars = c.GetSuperClassGenericTypeVars();
            Assert.AreEqual(scvars.Count, 1);
            var1 = scvars[0];
            Assert.AreEqual(var1.Name, "T");
            Assert.AreSame(var1.ReferredGenericTypeVar, vars[1]);

            // public class ImageSearch<I extends Image, X extends I, T extends MediaSearchResult<X>> extends MediaSearch<X, T>
            c      = ClassDescriptor.GetClassDescriptor(typeof(ImageSearch <, ,>));
            vars   = c.GetGenericTypeVars();
            scvars = c.GetSuperClassGenericTypeVars();
            Assert.AreEqual(scvars.Count, 2);
            var1 = scvars[0];
            Assert.AreEqual(var1.Name, "X");
            Assert.AreSame(var1.ReferredGenericTypeVar, vars[1]);
            GenericTypeVar var2 = scvars[1];

            Assert.AreSame(var2.ClassDescriptor, ClassDescriptor.GetClassDescriptor(typeof(MediaSearchResult <>)));
            Assert.AreEqual(var2.GenericTypeVarArgs.Count, 1);
            Assert.AreEqual(var2.GenericTypeVarArgs[0].Name, "X");
            Assert.AreSame(var2.GenericTypeVarArgs[0].ReferredGenericTypeVar, vars[1]);
        }