Resharper Custom Patterns: Ignore property attributes

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??


Tx
Y

1 comment
Comment actions Permalink

Hello Yoeri
     I'm afraid attributes cannot be preserved in this case. You're welcome to put a request through our bug tracker: http://youtrack.jetbrains.net/issues/RSRP. Thank you!

Andrey Serebryansky

Senior Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0

Please sign in to leave a comment.