public static MethodInstantiation Create(MethodInfo genericMethodDefinition = null, IEnumerable <Type> typeArguments = null) { genericMethodDefinition = genericMethodDefinition ?? NormalizingMemberInfoFromExpressionUtility.GetGenericMethodDefinition(() => GenericMethod(7)); typeArguments = typeArguments ?? genericMethodDefinition.GetGenericArguments().Select(a => ReflectionObjectMother.GetSomeType()); var instantiationInfo = new MethodInstantiationInfo(genericMethodDefinition, typeArguments); return(new MethodInstantiation(instantiationInfo)); }
public void SetUp() { _genericMethodDefinition = NormalizingMemberInfoFromExpressionUtility.GetGenericMethodDefinition(() => GenericMethod <Dev.T> (null)); _customType = CustomTypeObjectMother.Create(); _runtimeType = ReflectionObjectMother.GetSomeType(); _infoWithCustomType = new MethodInstantiationInfo(_genericMethodDefinition, new[] { _customType }.AsOneTime()); _infoWithRuntimeType = new MethodInstantiationInfo(_genericMethodDefinition, new[] { _runtimeType }); }
public void SetUp() { _typeParameter = MutableGenericParameterObjectMother.Create(); _parameter = CustomParameterInfoObjectMother.Create(); _genericMethodDefinition = CustomMethodInfoObjectMother.Create(parameters: new[] { _parameter }, typeArguments: new[] { _typeParameter }); _typeArgument = CustomTypeObjectMother.Create(); var info = new MethodInstantiationInfo(_genericMethodDefinition, new[] { _typeArgument }); _instantiation = new MethodInstantiation(info); }
public void Instantiate_CustomGenericMethodDefinition() { var typeParameter = ReflectionObjectMother.GetSomeGenericParameter(); var customGenericMethodDefinition = CustomMethodInfoObjectMother.Create(typeArguments: new[] { typeParameter }); var instantiationInfo = new MethodInstantiationInfo(customGenericMethodDefinition, new[] { _runtimeType }); var result = instantiationInfo.Instantiate(); Assert.That(result, Is.TypeOf <MethodInstantiation>()); Assert.That(result.GetGenericMethodDefinition(), Is.EqualTo(instantiationInfo.GenericMethodDefinition)); Assert.That(result.GetGenericArguments(), Is.EqualTo(instantiationInfo.TypeArguments)); }
/// <summary> /// Substitutes the type parameters of the generic type definition and returns a <see cref="MethodInfo"/> object representing the resulting /// constructed method. Use this as a replacement for <see cref="MethodInfo.MakeGenericMethod"/>. /// </summary> /// <param name="genericMethodDefinition">The generic method definition.</param> /// <param name="typeArguments">The type arguments.</param> /// <returns>The generic method instantiation.</returns> public static MethodInfo MakeTypePipeGenericMethod(this MethodInfo genericMethodDefinition, params Type[] typeArguments) { ArgumentUtility.CheckNotNull("genericMethodDefinition", genericMethodDefinition); ArgumentUtility.CheckNotNullOrItemsNull("typeArguments", typeArguments); if (!genericMethodDefinition.IsGenericMethodDefinition) { var message = string.Format( "'{0}' is not a generic method definition. MakeTypePipeGenericMethod may only be called on a method for which " + "MethodInfo.IsGenericMethodDefinition is true.", genericMethodDefinition.Name); throw new InvalidOperationException(message); } var typeParameters = genericMethodDefinition.GetGenericArguments(); GenericArgumentUtility.ValidateGenericArguments(typeParameters, typeArguments, genericMethodDefinition.Name); var instantiationInfo = new MethodInstantiationInfo(genericMethodDefinition, typeArguments); return(instantiationInfo.Instantiate()); }