Auto generate Properties
Hi,
I'm currently trying to auto generate the backing field and property for a variable. Currently my template looks like:
/// <summary>
/// Backing Field for the <see cref="$PROPERTY_NAME$" />
/// </summary>
private $TYPE$ $TARGET_PROPERTY$;
/// <summary>
/// Gets or sets $PROPERTY_NAME$.
/// </summary>
public $TYPE$ $PROPERTY_NAME$
{
get
{
return this.$TARGET_PROPERTY$;
}
set
{
if (!Equals(value, this.$TARGET_PROPERTY$))
{
this.$TARGET_PROPERTY$ = value;
this.NotifyOfPropertyChange("$PROPERTY_NAME$");
}
}
}
But what I want is to be able to place the property section after the constructor of the class if it's there else just place it at the end of the file. Is this possible or do I need to cut and paste each time I create a new variable?
Please sign in to leave a comment.
The placement would be wherever you want using the Type Members Layout (ReSharper | Options | C#).
How do you invoke that automatically though?
Edit:
I should possibly clarify this. I want to be able to use the live template to type abc where the private fields are meant to go (top of the file) this would then create the private field there and the public property at the bottom of the file
Hello Tim,
Could you please clarify how exactly do you use this template to auto-generate
properties? Thank you!
Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
since it's created as a Live template I use the keyword formatting
Hello Tim,
I see. I'm afraid such behavior can not be achieved automatically with live
templates only. After inserting such template, you should run Code Cleanup
with a profile that includes 'Reorder members' stage, so that field and property
get ordered according to type member layout. Thank you!
Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
Was hoping there was a neater way of doing it but ah well, thanks for the reply