private void ResolveMethod() { int genericParameterCount = method.IsGenericMethodDefinition ? method.GenericArguments.Count : 0; resolvedGenericArguments = new Type[genericParameterCount]; int seen = 0; foreach (KeyValuePair <ISlotInfo, object> slotValue in SlotValues) { IGenericParameterInfo genericParameter = slotValue.Key as IGenericParameterInfo; if (genericParameter != null) { resolvedGenericArguments[genericParameter.Position] = (Type)Converter.Convert(slotValue.Value, typeof(Type)); seen += 1; } } if (genericParameterCount != seen) { throw new ArgumentException(String.Format("The method has {0} generic parameters but the bindings only provide values for {1} of them.", genericParameterCount, seen)); } resolvedMethod = ResolveMember(resolvedType, method.Resolve(true)); if (genericParameterCount != 0) { resolvedMethod = resolvedMethod.MakeGenericMethod(resolvedGenericArguments); } }
/// <inheritdoc /> protected override void DecorateContainingScope(IPatternScope containingScope, IMethodInfo methodInfo) { Type formattableType = methodInfo.Parameters[0].Resolve(true).ParameterType; var extensionPoints = (IExtensionPoints)RuntimeAccessor.ServiceLocator.ResolveByComponentId("Gallio.ExtensionPoints"); CustomTestEnvironment.SetUpThreadChain.Before(() => extensionPoints.CustomFormatters.Register(formattableType, x => (string)methodInfo.Resolve(true).Invoke(this, new[] { x }))); CustomTestEnvironment.TeardownThreadChain.After(() => extensionPoints.CustomFormatters.Unregister(formattableType)); }
/// <inheritdoc /> protected override void DecorateContainingScope(IPatternScope containingScope, IMethodInfo method) { MethodInfo factoryMethod = method.Resolve(false); if (factoryMethod == null || Reflector.IsUnresolved(factoryMethod)) { containingScope.TestModelBuilder.AddAnnotation(new Annotation(AnnotationType.Info, method, "This test runner does not fully support static test factory methods " + "because the code that defines the factory cannot be executed " + "at test exploration time. Consider using dynamic test factory " + "methods instead.")); return; } var tests = factoryMethod.Invoke(null, null) as IEnumerable <Test>; if (tests == null) { containingScope.TestModelBuilder.AddAnnotation(new Annotation(AnnotationType.Error, method, "Expected the static test factory method to return a value that is assignable " + "to type IEnumerable<Test>.")); return; } Test.BuildStaticTests(tests, containingScope, method); }
/// <inheritdoc /> protected override void DecorateContainingScope(IPatternScope containingScope, IMethodInfo methodInfo) { Type sourceType = methodInfo.Parameters[0].Resolve(true).ParameterType; Type targetType = methodInfo.ReturnType.Resolve(true); MethodInfo method = methodInfo.Resolve(true); var extensionPoints = (IExtensionPoints)RuntimeAccessor.ServiceLocator.ResolveByComponentId("Gallio.ExtensionPoints"); CustomTestEnvironment.SetUpThreadChain.Before(() => extensionPoints.CustomConverters.Register(sourceType, targetType, x => method.Invoke(this, new[] { x }))); CustomTestEnvironment.TeardownThreadChain.After(() => extensionPoints.CustomConverters.Unregister(sourceType, targetType)); }
public override MethodInfo GetGenericMethodDefinition() { IMethodInfo genericMethodDefinition = adapter.GenericMethodDefinition; if (genericMethodDefinition == null) { throw new InvalidOperationException("The method is not generic."); } return(genericMethodDefinition.Resolve(false)); }
private static RequestedAction CallProcessFinalBitmap(BuilderExtension plugin, ImageState state) { ITypeInfo type = Reflector.Wrap(plugin.GetType()); IMethodInfo method = type.GetMethod("ProcessFinalBitmap", BindingFlags.Instance | BindingFlags.NonPublic); Assert.IsNotNull(method, "Did not find 'ProcessFinalBitmap' method on plugin."); MethodInfo m = method.Resolve(false); Assert.IsNotNull(m); RequestedAction requestedAction = (RequestedAction)m.Invoke(plugin, new object[] { state }); return(requestedAction); }
private static Type ResolveGenericParameter(IGenericParameterInfo genericParameter, MethodInfo methodContext) { IMethodInfo declaringMethod = genericParameter.DeclaringMethod; if (declaringMethod != null) { if (methodContext == null) { methodContext = declaringMethod.Resolve(true); } return(methodContext.GetGenericArguments()[genericParameter.Position]); } return(genericParameter.DeclaringType.Resolve(true).GetGenericArguments()[genericParameter.Position]); }
/// <inheritdoc /> protected override void DecorateContainingScope(IPatternScope containingScope, IMethodInfo methodInfo) { Type comparableType = methodInfo.Parameters[0].Resolve(true).ParameterType; CustomTestEnvironment.SetUpThreadChain.Before(() => Register(comparableType, (x, y) => methodInfo.Resolve(true).Invoke(this, new[] { x, y }))); CustomTestEnvironment.TeardownThreadChain.After(() => Unregister(comparableType)); }
public static MethodInfo ResolveMethod(IMethodInfo method, bool nonPublic) { return(method != null && (nonPublic || method.IsPublic) ? method.Resolve(false) : null); }
public static MethodInfo ResolveMethod(IMethodInfo method, bool nonPublic) { return method != null && (nonPublic || method.IsPublic) ? method.Resolve(false) : null; }
private GallioFunc <object[], TOutput> TryGetMemberAsMethod(FixtureMemberInvokerTargets targets, ITypeInfo ownerInfo) { if ((targets & FixtureMemberInvokerTargets.Method) != 0) { IMethodInfo info = ownerInfo.GetMethod(memberName, bindingFlags); if (info != null) { return(args => { object fixtureInstance = GetFixtureInstance(info.IsStatic); MethodInfo method = (type == null) ? GetMemberInfo <MethodInfo>(t => t.GetMethod(memberName, bindingFlags)) : info.Resolve(true); if (method == null) { throw new TestFailedException(String.Format("Could not find method '{0}'.", memberName)); } object[] convertedArgs = ConvertArguments(method.GetParameters(), args); return (TOutput)method.Invoke(fixtureInstance, convertedArgs); }); } } return(null); }
/// <inheritdoc /> protected override void DecorateContainingScope(IPatternScope containingScope, IMethodInfo method) { MethodInfo factoryMethod = method.Resolve(false); if (factoryMethod == null || Reflector.IsUnresolved(factoryMethod)) { containingScope.TestModelBuilder.AddAnnotation(new Annotation(AnnotationType.Info, method, "This test runner does not fully support static test factory methods " + "because the code that defines the factory cannot be executed " + "at test exploration time. Consider using dynamic test factory " + "methods instead.")); return; } var tests = factoryMethod.Invoke(null, null) as IEnumerable<Test>; if (tests == null) { containingScope.TestModelBuilder.AddAnnotation(new Annotation(AnnotationType.Error, method, "Expected the static test factory method to return a value that is assignable " + "to type IEnumerable<Test>.")); return; } Test.BuildStaticTests(tests, containingScope, method); }