/// <summary> /// Computes the value for <see cref="ParameterTypes"/> with bound generic parameters. /// </summary> /// <param name="substitutor">The type substitutor to use for generic parameter binding.</param> /// <returns>The bound types to expose in <see cref="ParameterTypes"/>.</returns> private ReadOnlyCollection <TypeSlim> GetParameterTypes(TypeSlimSubstitutor substitutor) { var parameterTypesCount = GenericMethodDefinition.ParameterTypes.Count; var parameterTypes = new TypeSlim[parameterTypesCount]; for (var i = 0; i < parameterTypesCount; ++i) { parameterTypes[i] = substitutor.Visit(GenericMethodDefinition.ParameterTypes[i]); } return(new TrueReadOnlyCollection <TypeSlim>(/* transfer ownership */ parameterTypes)); }
public void TypeSubstitutor_Array() { var subst = new TypeSlimSubstitutor( new Dictionary <TypeSlim, TypeSlim> { { typeof(int[]).ToTypeSlim(), typeof(long[]).ToTypeSlim() } }); AssertIsNull(null, subst); AssertUnchanged(typeof(string), subst); AssertUnchanged(typeof(List <string[]> [, ]), subst); AssertUnchanged(typeof(int), subst); AssertAreEqual(typeof(long[]), typeof(int[]), subst); AssertUnchanged(typeof(int[, ]), subst); AssertUnchanged(typeof(Func <int>), subst); AssertAreEqual(typeof(Func <bool, Func <object, long[]>, double>), typeof(Func <bool, Func <object, int[]>, double>), subst); }
/// <summary> /// Computes the value for <see cref="ReturnType"/> with bound generic parameters. /// </summary> /// <param name="substitutor">The type substitutor to use for generic parameter binding.</param> /// <returns>The bound type to expose in <see cref="ReturnType"/>.</returns> private TypeSlim GetReturnType(TypeSlimSubstitutor substitutor) { return(substitutor.Visit(GenericMethodDefinition.ReturnType)); }
private static void AssertAreEqual(Type expected, Type target, TypeSlimSubstitutor substitutor) { Assert.IsTrue(expected.ToTypeSlim().Equals(substitutor.Visit(target.ToTypeSlim()))); }
private static void AssertUnchanged(Type type, TypeSlimSubstitutor substitutor) { var typeSlim = type.ToTypeSlim(); Assert.AreSame(typeSlim, substitutor.Visit(typeSlim)); }
private static void AssertIsNull(TypeSlim type, TypeSlimSubstitutor substitutor) { Assert.IsNull(substitutor.Visit(type)); }