public void InstantiatedMethodByParameterTest() { // build "T MyMethod<T> (T[] a)" DomMethod method = new DomMethod(); method.Name = "MyMethod"; method.ReturnType = new DomReturnType("T"); method.AddTypeParameter(new TypeParameter("T")); DomReturnType returnType = new DomReturnType("T"); returnType.ArrayDimensions = 1; method.Add(new DomParameter(method, "a", returnType)); // give int[] as param type. List <IReturnType> genArgs = new List <IReturnType> (); List <IReturnType> args = new List <IReturnType> (); returnType = new DomReturnType(DomReturnType.Int32.FullName); returnType.ArrayDimensions = 1; args.Add(returnType); IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod(method, genArgs, args); // check (note that return type should be int and not int[]) Assert.AreEqual(DomReturnType.Int32.FullName, instMethod.ReturnType.FullName); Assert.AreEqual(0, instMethod.ReturnType.ArrayDimensions); Assert.AreEqual(DomReturnType.Int32.FullName, instMethod.Parameters[0].ReturnType.FullName); }
public void InstantiatedMethodByArgumentTest_Complex() { // build "T MyMethod<T,S> (S b, KeyValuePair<S, T> a)" DomMethod method = new DomMethod(); method.Name = "MyMethod"; method.ReturnType = new DomReturnType("T"); method.AddTypeParameter(new TypeParameter("T")); method.AddTypeParameter(new TypeParameter("S")); method.Add(new DomParameter(method, "b", new DomReturnType("S"))); DomReturnType returnType = new DomReturnType("KeyValuePair"); returnType.AddTypeParameter(new DomReturnType("T")); returnType.AddTypeParameter(new DomReturnType("S")); method.Add(new DomParameter(method, "a", returnType)); // give int, object as param type List <IReturnType> genArgs = new List <IReturnType> (); List <IReturnType> args = new List <IReturnType> (); genArgs.Add(DomReturnType.Int32); genArgs.Add(DomReturnType.Object); IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod(method, genArgs, args); // check Assert.AreEqual(DomReturnType.Int32.FullName, instMethod.ReturnType.FullName); Assert.AreEqual(DomReturnType.Object.FullName, instMethod.Parameters[0].ReturnType.FullName); Assert.AreEqual(DomReturnType.Int32.FullName, instMethod.Parameters[1].ReturnType.GenericArguments[0].FullName); Assert.AreEqual(DomReturnType.Object.FullName, instMethod.Parameters[1].ReturnType.GenericArguments[1].FullName); }
public void InstantiatedMethodByArgumentTestComplex2() { // build "T MyMethod<T> (MyType<T> a)" DomMethod method = new DomMethod(); method.Name = "MyMethod"; method.ReturnType = new DomReturnType("T"); method.AddTypeParameter(new TypeParameter("T")); DomReturnType returnType = new DomReturnType("MyType"); returnType.AddTypeParameter(new DomReturnType("T")); method.Add(new DomParameter(method, "a", returnType)); // give int as param type List <IReturnType> genArgs = new List <IReturnType> (); List <IReturnType> args = new List <IReturnType> (); returnType = new DomReturnType("MyType"); returnType.AddTypeParameter(DomReturnType.Int32); args.Add(returnType); IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod(method, genArgs, args); // check Assert.AreEqual(DomReturnType.Int32.FullName, instMethod.ReturnType.FullName); }