Ejemplo n.º 1
0
        public virtual void TestGetClass()
        {
            //test with Integer
            int  x = 42;
            Type c = GenericsUtil.GetClass(x);

            Assert.Equal("Correct generic type is acquired from object", typeof(
                             int), c);
            //test with GenericClass<Integer>
            TestGenericsUtil.GenericClass <int> testSubject = new TestGenericsUtil.GenericClass
                                                              <int>(this);
            Type c2 = GenericsUtil.GetClass(testSubject);

            Assert.Equal("Inner generics are acquired from object.", typeof(
                             TestGenericsUtil.GenericClass), c2);
        }
Ejemplo n.º 2
0
 public virtual void TestWithGenericClass()
 {
     TestGenericsUtil.GenericClass <string> testSubject = new TestGenericsUtil.GenericClass
                                                          <string>(this);
     testSubject.Add("test1");
     testSubject.Add("test2");
     try
     {
         //this cast would fail, if we had not used GenericsUtil.toArray, since the
         //rmethod would return Object[] rather than String[]
         string[] arr = testSubject.FuncThatUsesToArray();
         Assert.Equal("test1", arr[0]);
         Assert.Equal("test2", arr[1]);
     }
     catch (InvalidCastException)
     {
         Fail("GenericsUtil#toArray() is not working for generic classes");
     }
 }