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
Please sign in to leave a comment.
Hello Peter,
Please, modify defaultBodyTemplate in Special folder of ReSharper Live Templates.
Best regards,
Andrey Simanovsky
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
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
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.
Best regards,
Andrey Simanovsky