question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support Raise.With for arbitrary delegates without requiring a typeparam in the call.

See original GitHub issue

Update (@blairconrad): title changed after initial discussion among owners. I’ve left the original proposal here, but the goal of the issue has been expanded include support for all non-EventHandler delegates.


Documentation says you have to specify generic type for Raise.With in case you use a custom delegate. And as I understand by “custom delegate” it measn everything besides EventHandler (which is not that popular for handling events besides Windows Forms). Would be nice to add support for Action and Func delegates as most of events are designed using them. Now we have to write something likes this:

realtimeManager.ConnectionStateChanged += Raise.With<Action<ConnectionState>>(ConnectionState.Connected);

instead of

realtimeManager.ConnectionStateChanged += Raise.With(ConnectionState.Connected);

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:28 (26 by maintainers)

github_iconTop GitHub Comments

1reaction
thomaslevesquecommented, Apr 20, 2017

I have a POC for my dynamic idea. It lets you do this:

void Main()
{
    var foo = A.Fake<IFoo>();
    foo.Bar += (first, last) =>
    {
        Console.WriteLine($"Hello {first} {last}!");
    };
    foo.Bar += Raise.WithD("John", "Doe");
}

public delegate void MyHandler(string firstName, string lastName);
public interface IFoo
{
    event MyHandler Bar;
}

(note that I had to use a different name for With to avoid the ambiguity I mentioned above; obviously we would have to pick a better name)

Assignment to something other than a delegate or event with the correct signature throws an exception.

0reactions
blairconradcommented, Jul 27, 2017

Glad you like the look of it @siberianguy. And as I type, NuGet has just finished indexing the packages. You can try it out right now!

Read more comments on GitHub >

github_iconTop Results From Across the Web

In a C# event handler, why must the "sender" parameter be ...
It does mean that one component can forward on an event from another, keeping the original sender even if it's not the normal...
Read more >
Changes in version 2.0 - FakeItEasy - Read the Docs
Raising custom event handler events now require a typeparam (but neither Now nor Go ). (#30) For example: public delegate void CustomEventHandler(object ...
Read more >
Function Pointers, Serialization, and General Workflow
Hello, I have a few questions involving function pointers. I know that technically function pointers are serializable, but my first test ...
Read more >
ASP.NET Core Blazor performance best practices
Tips for increasing performance in ASP.NET Core Blazor apps and avoiding common performance problems.
Read more >
FakeItEasy/FakeItEasy 4.0.0-beta001 on GitHub
... member without first specifying Returns (#1134); Support raising events for arbitrary delegates without requiring a typeparam in the call ( Raise.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found