Drag custom templates: ignore property attributes

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$]
...

, , .

+5
2

, .
( ), . , . Surround Template, () = > PropName. . :

enter image description here

.
: , , Ctrl + E, Ctrl + U String func.

, . , .

+2

. VS , . .

?

. replace, brgerner, . , OnPropertyChanged\("{:w*}"\);, replace OnPropertyChanged(() => \1);

, Resharper.

0

All Articles