I am writing several Resarper Custom Patterns to alert us to some code designs that need attention. One of them replaces OnpropertyChanged ("String") with the lambda variant OnPropertyChanged (() => propertyname)
Your search pattern:
public $type$ $property$
{
get { return $backingfield$; }
set
{
if($backingfield$ != value) {
$backingfield$ = value;
OnPropertyChanged($String$);
}
}
}
This template is replaced by:
public $type$ $property$
{
get { return $backingfield$; }
set
{
if($backingfield$ != value) {
$backingfield$ = value;
OnPropertyChanged(() => $property$);
}
}
}
Problem:
When applying this, Resharper discards the attributes defined in the property. This snippet:
[MyAttribute]
public int Test
{
get { return _Test; }
set
{
if (_Test != value)
{
_Test = value;
OnPropertyChanged("Test");
}
}
}
replaced by
public int Test
{
get { return _Test; }
set
{
if (_Test != value)
{
_Test = value;
OnPropertyChanged(() => Test);
}
}
}
How to save attributes
UPDATE : Adding a placeholder of a type derived from System.Attribute to the search and replace pattern fixes it partially.
[$Attributes$]
...
, , .