Is it possible to change Generation Templates?

I'd like to change the code that is generated when I implement methods from an interface (in particular, the code that is generated when implementing an Event). I heard mention that this would be a 2.0 feature, yet I cannot find anywhere I can do this in 2.5...

Pete

4 comments
Comment actions Permalink

Hello Peter,

Please, modify defaultBodyTemplate in Special folder of ReSharper Live Templates.

I'd like to change the code that is generated when I implement methods
from an interface (in particular, the code that is generated when
implementing an Event). I heard mention that this would be a 2.0
feature, yet I cannot find anywhere I can do this in 2.5...

Pete

Best regards,
Andrey Simanovsky


0
Comment actions Permalink

Hi Andrey,
While this is helpful, it's not quite what I had in mind... If I implement an interface that exposes an Event, the following code gets generated:

public event MoveMadeEventHandler MoveMade
{
add { throw new NotImplementedException(); }
remove { throw new NotImplementedException(); }
}

When I would like the following code generated:

public event MoveMadeEventHandler MoveMade;

protected virtual void OnMoveMade(MoveMadeEventArgs moveMadeEventArgs)
{
MoveMadeEventHandler tmp = MoveMade;

if (tmp != null) {
tmp(this, moveMadeEventArgs);
}
}

Is it possible to change the templates at this level?

Pete

0
Comment actions Permalink

Same question, but for properties. I would like to have the setter check it's value and setting it only upon a different value. Furthermore I would like to raise a propertychanged event.

Therefore I would like to adjust the default templates.

Is this possible?

Jan

0
Comment actions Permalink

Hello Jan,

At present the default body template is shared among all generate actions
that create function body. Generate behavior is not adjustable with repect
to backing fields.
You can consider creating custom live template and invoking it to generate
properties with special behavior.
We consider more flexible generate actions for future versions.

Same question, but for properties. I would like to have the setter
check it's value and setting it only upon a different value.
Furthermore I would like to raise a propertychanged event.

Therefore I would like to adjust the default templates.

Is this possible?

Jan

Best regards,
Andrey Simanovsky


0

Please sign in to leave a comment.