5 comments
Comment actions Permalink

It would also be nice to have some kind of pre-runtime warning when this is missed...

0
Comment actions Permalink

I think the best way to insert such thing is to have a live template for
this case.

--
Oleg Stepanov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Oskar Austegard" <no_mail@jetbrains.com> wrote in message
news:615188.1081946500047.JavaMail.javamailuser@localhost...

Say I have an event declared as

 public event System.EventHandler ToolNewClick;]]>

In order to properly invoke this (according to the C# team @

http://blogs.msdn.com/csharpfaq/archive/2004/03/19/93082.aspx) I have to
write code like

 EventHandler toolNewClick = ToolNewClick;
> if (toolNewClick != null)
> toolNewClick(e.Tool, new EventArgs());
> ]]>

It would be nice if this could be done through pressing Alt+Insert and

selecting the event to invoke.
>

Thanks,
Oskar



0
Comment actions Permalink

Yes, live template for event as a complete pattern is what I vote for. Including event statement, and protected virtual invocation method. However there is potential problem that signature for method depends on delegate choosen. If delegate conforms to guidelines (object sender, NNNEventArgs e), that method should get single NNNEventArgs as paramter and invoke delegate with 'this' as a sender. If delegate has different signature, it can be not obvious what should be invocation method's signature.

Another point, is that in Component there is slightly different event implementation model. When there are many events and most of them are unlikely to be used (e.g.
PropertyChanged events), developer may want to use events dictionary rather then individual delegates. See protected Events property in Component class. Here is how the code looks like:


So it's not obvious, how LiveTemplate should work for events.

0
Comment actions Permalink

There should be special live template macro which detects delegate
parameters and produces method with corresponding signature. Regarding the
non-standard behaviour you highlighted - ReSharper simply can't support all
individual approaches to event handling, so we'll leave this case away.

--
Oleg Stepanov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Ilya Ryzhenkov" <no_mail@jetbrains.com> wrote in message
news:27536859.1081954484621.JavaMail.javamailuser@localhost...

Yes, live template for event as a complete pattern is what I vote for.

Including event statement, and protected virtual invocation method. However
there is potential problem that signature for method depends on delegate
choosen. If delegate conforms to guidelines (object sender, NNNEventArgs e),
that method should get single NNNEventArgs as paramter and invoke delegate
with 'this' as a sender. If delegate has different signature, it can be not
obvious what should be invocation method's signature.
>

Another point, is that in Component there is slightly different event

implementation model. When there are many events and most of them are
unlikely to be used (e.g.

PropertyChanged events), developer may want to use events dictionary

rather then individual delegates. See protected Events property in Component
class. Here is how the code looks like:
>

> public event EventHandler DataChanged
> {
> add
> {
> Events.AddHandler(EventDataChanged, value); // add handler to table
> }
> remove
> {
> Events.RemoveHandler(EventDataChanged, value); // remove handler from
table
> }
> }
>
> protected virtual void OnDataChanged(EventArgs e)
> {
> EventHandler eventHandler = (EventHandler)Events[EventDataChanged]; // get
handler
> if (eventHandler != null) // call subscribers
> eventHandler(this, e);
> }]]>

>

So it's not obvious, how LiveTemplate should work for events.



0
Comment actions Permalink

What is "corresponding" signature? Do you mean that (object sender, ZZZEventArgs e) become (ZZZEventArgs e) for method and all other are copied as is?

For the special case: Yes, Re#er cannot handle all individual approaches, but in C# there are two ways to specify an event (one is shortcut of another):

public event EventHandler MyEvent;

and

private EventHandler _myEvent;
public event EventHandler MyEvent
{
add { myEvent = (EventHandler)Delegate.Combine(myEvent, value); }
remove { myEvent = (EventHandler)Delegate.Remove(myEvent, value); }
}

And these two cases should be covered by Re#er. I thought about "Expand event" refactory, which converts first kind to second, but this is up to you.

0

Please sign in to leave a comment.