StephenCleary / AsyncEx

A helper library for async/await.
MIT License
3.53k stars 356 forks source link

Feature request: base class for event args #87

Open StephenCleary opened 7 years ago

StephenCleary commented 7 years ago

From @grokky1 on April 9, 2017 11:43

Many (in my experience, most) event handlers use event args without data. So this is boilerplate:

public class AsyncEventArgs : EventArgs, IDeferralSource
{
  internal DeferralManager DeferralManager { get; } = new DeferralManager();
  public IDisposable GetDeferral() => DeferralManager.DeferralSource.GetDeferral();
}

So would you kindly consider adding it to the library? Would make calling code mush cleaner.

If someone needs eventargs with data, then just subclass AsyncEventArgs. Which would also be cleaner.

Copied from original issue: StephenClearyArchive/AsyncEx.Oop#1

StephenCleary commented 7 years ago

Yes, absolutely! I just read a blog post last week where someone used a base class for this, and thought it would be a good idea.

The only real question is how the internal member should be exposed. Possibly keep it internal and just add event-raising helpers...

StephenCleary commented 7 years ago

From @grokky1 on April 9, 2017 12:11

I've only just started using your library so not sure. But to keep it simple, for now I've declared it as public.