private static void TestGenericReturnSpecificForMethod() { var theClass = new MethodsWithGeneric <int, int>(); var value1 = theClass.GenericAtMethod <string>("test"); Assert("test", value1); var value2 = theClass.GenericAtMethod("test2"); Assert("test2", value2); var value3 = theClass.GenericAtMethod <bool>(true); Assert("True", value3); var value4 = theClass.GenericAtMethod <ClassA>(new ClassA("test4")); Assert("test4", value4); var obj = new ClassA("test5"); var value5 = theClass.GenericAtMethod(obj); Assert("test5", value5); }
private static void TestGenericsInAmbMethods() { var theClass = new MethodsWithGeneric <int, int>(); Assert("XYA", theClass.GenericAtAmbMethod <string, string>("X", "Y")); Assert("XYB", theClass.GenericAtAmbMethod <string>("X", "Y")); Assert("XYB", theClass.GenericAtAmbMethod("X", "Y")); Assert("X1A", theClass.GenericAtAmbMethod("X", 1)); }
private static void TestMethodGenericAsGenericInInputObject() { var theClass = new MethodsWithGeneric <int, int>(); var a = theClass.MethodWithGenericAsObjectGenericInArg((() => 3)); var b = theClass.MethodWithGenericAsObjectGenericInArg((() => "x")); Assert(3, a); Assert("x", b); }
private static void TestGenericMethod() { var theClass = new MethodsWithGeneric <int, string>(); theClass.AmbGenericMethod(1); Assert("GenericMethodT1", Output); ResetOutput(); theClass.AmbGenericMethod("x"); Assert("GenericMethodT2", Output); }
private static void TestGenericReturnArg() { var theClass = new MethodsWithGeneric <int, int>(); var value1 = theClass.GenericReturnType <bool>(true); Assert(true, value1); var value2 = theClass.GenericReturnType <string>("test"); Assert("test", value2); }
private static void TestGenericsInStaticMethods() { Assert("String", MethodsWithGeneric <int, int> .StaticMethodWithGenerics("X")); Assert("String", MethodsWithGeneric <int, int> .StaticMethodWithGenerics <string>("X")); Assert("Int32", MethodsWithGeneric <int, int> .StaticMethodWithGenerics <int>(43)); }
public ClassUsingGenericsInMethods() { this.inner = new MethodsWithGeneric <T, int>(); }