/// <summary> /// Initializes a new instance of the <see cref="DelegateRaiser{TEventHandler}"/> class. /// </summary> /// <param name="arguments">The arguments to be sent to the event handler.</param> /// <param name="argumentProviderMap">A map from event handlers to supplied arguments to use when raising.</param> public DelegateRaiser(object?[] arguments, EventHandlerArgumentProviderMap argumentProviderMap) { var delegateMethod = typeof(TEventHandler).GetMethod("Invoke"); ValueProducerSignatureHelper.AssertThatValuesSatisfyCallSignature(delegateMethod, arguments); this.EventHandler = A.Fake <TEventHandler>(); this.EventArguments = arguments; argumentProviderMap.AddArgumentProvider(this.EventHandler, this); }
public override bool TryConvert(ConvertBinder binder, out object result) { var targetType = binder.Type; if (!targetType.IsSubclassOf(typeof(Delegate))) { throw new InvalidCastException(ExceptionMessages.UnableToCast(this.GetType(), targetType)); } var method = targetType.GetMethod("Invoke") !; ValueProducerSignatureHelper.AssertThatValuesSatisfyCallSignature(method, this.arguments); var @delegate = (Delegate)Create.Fake(targetType); this.argumentProviderMap.AddArgumentProvider(@delegate, this); result = @delegate; return(true); }