I am writing some Resarper Custom Patterns to warn us about some code constructs that need attention. One of these is replacing OnpropertyChanged("String") with a lambda variant OnPropertyChanged(() => propertyname)
The search Pattern I defined is:
public $type$ $property$
{
get { return $backingfield$; }
set
{
if($backingfield$ != value) {
$backingfield$ = value;
OnPropertyChanged($String$);
}
}
}
This pattern is being replaced with:
public $type$ $property$
{
get { return $backingfield$; }
set
{
if($backingfield$ != value) {
$backingfield$ = value;
OnPropertyChanged(() => $property$);
}
}
}
Problem: When applying this, Resharper throws away the attributes defined on the property. This snippet:
[MyAttribute]
public int Test
{
get { return _Test; }
set
{
if (_Test != value)
{
_Test = value;
OnPropertyChanged("Test");
}
}
}
gets replaced with
public int Test
{
get { return _Test; }
set
{
if (_Test != value)
{
_Test = value;
OnPropertyChanged(() => Test);
}
}
}
How can I preserve the attributes??
UPDATE: Adding a type placeholder derived from System.Attribute to both search and replace pattern fixes it partially.
[$Attributes$]
...
Remaining problem is that the Attribute placeholder only matches one attribute, it fails on multiple attributes.