Implementing Interface & Handling Event Properties

Hi!
If I add an event to an interface:

event LoadedObjectEventHandler ObjectsLoaded;

automatically, R# indicates me that the classes that implement that interface require the event, and if I tell R# that "I agree" it generates the following code:

public event LoadedObjectEventHandler ObjectsLoaded;

but I would like it more if the following happened:

Add a Field:
LoadedObjectEventHandler objectsLoaded;
Add a Property to Encapsulate it:
public event LoadedObjectEventHandler ObjectsLoaded
{
add {
objectsLoaded+=value;
}
remove {
objectsLoaded-=value;
}
}

By the way, if I try to do an "Encapsulate Field" on "LoadedObjectEventHandler objectsLoaded;" I get:

public LoadedObjectEventHandler ObjectsLoaded
{
get{
return objectsLoaded;
}
set{
objectsLoaded=value;
}
}

which... IMHO... is incorrect... am I wrong?

thanks

0
3 comments
Avatar
Francisco Peredo

So... will this be implemented for the next release?

0

Hello,

Hi!
If I add an event to an interface:
event LoadedObjectEventHandler ObjectsLoaded;

automatically, R# indicates me that the classes that implement that
interface require the event, and if I tell R# that "I agree" it
generates the following code:

public event LoadedObjectEventHandler ObjectsLoaded;

but I would like it more if the following happened:

Add a Field:
LoadedObjectEventHandler objectsLoaded;
Add a Property to Encapsulate it:
public event LoadedObjectEventHandler ObjectsLoaded
{
add {
objectsLoaded+=value;
}
remove {
objectsLoaded-=value;
}
}


In version 2.0 ReSharper will allow to modify generation templates. A user
will be able to customize the templates for the implementation of events.
I think that covers your request.

By the way, if I try to do an "Encapsulate Field" on
"LoadedObjectEventHandler objectsLoaded;" I get:

public LoadedObjectEventHandler ObjectsLoaded
{
get{
return objectsLoaded;
}
set{
objectsLoaded=value;
}
}
which... IMHO... is incorrect... am I wrong?

thanks

It depends on what a user needs. A user might want to create a field contating
the delegate. I agree that a need of event is more likely. We will consider
a way to effectively encapsulate an event in the case you describe. But that
is in version 2.0 as well.


0

So... will this be implemented for the next release?

Yes. Though I cannot tell about the change in Incapsulate Field. We might
do something else rather than change Encapsulate Field. Anyhow, the number
of key strokes required to create an event will be very small.:)


0

Please sign in to leave a comment.