use auto-property in code cleanup not working?

Hello, I've defined a custom code cleanup profile and have selected the option "Use auto-property, if possible", but when I run my cleanup on a given file, no properties are ever converted to auto-properties.  If I use the shortcut Alt+Enter on a given property, I get the option to convert it to an auto-property, and it works fine.

My files are very straight-forward.  They have one field per property, and standard get {} set {} operations.

I am using ReSharper 5.1 with Visual Studio 2010.

Am I missing something?

7 comments

Hello Nicholas,

I'm afraid I wasn't able to reproduce this behavior. Could you please attach
a small sample solution, a screenshot of your code cleanup profile settings
and provide exact steps you've performed, so that we could repeat this behavior
on our side? Thank you!

Andrey Serebryansky
Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Hello, I've defined a custom code cleanup profile and have selected
the option "Use auto-property, if possible", but when I run my cleanup
on a given file, no properties are ever converted to
auto-properties.  If I use the shortcut Alt+Enter on a given property,
I get the option to convert it to an auto-property, and it works fine.

My files are very straight-forward.  They have one field per property,
and standard get {} set {} operations.

I am using ReSharper 5.1 with Visual Studio 2010.

Am I missing something?

---
Original message URL:
http://devnet.jetbrains.net/message/5268923#5268923



0

I have this same scenario in v4.5

Code cleanup does nothing, but I get the prompt to convert on individual properties which works fine.

0

When I create sample solutions with dummy classes, the functionality seems to work fine.  So perhaps it's a solution-specific problem.  Unfortunately I can't post the problem solution because the code is proprietary.  If I happen to run into the issue in another solution I will post it here.

For what it's worth, here is my cleanup configuration:

CleanupOptions.png

0

I ran into this behavior today.  It is related (in my case) to generated code which is marked with the SerializableAttribute.  The following class will not have its property changed to an automatic property by R#.

using System;

namespace DataContracts
{
    [Serializable]
    public class Class1
    {
        private bool _wontChange;

        public bool WontChange
        {
            get { return _wontChange; }
            set { _wontChange = value; }
        }
    }
}

If you remove the SerializableAttribute decoration, R# will change the property.

0

I double-checked the original code I was working with -- sure enough, it was code generated with wsd.exe with the [Serializable] attribute.

0

Hello Matt,

Thank you for noticing this! Actually ReSharper behaves correctly in this
case. Here's an issue in our tracker that describes why converting properties
to auto-properties can be dangerous for serializable types: http://youtrack.jetbrains.net/issue/RSRP-63531.


Andrey Serebryansky
Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

using System;
namespace DataContracts
{

public class Class1
{
private bool _wontChange;
public bool WontChange
{
get { return _wontChange; }
set { _wontChange = value; }
}
}
}



0

Thanks Andrey.  Because of the brevity of discussion on that issue, I've added an SO question about serializing auto properties in general (as prompted by this feature) - http://stackoverflow.com/questions/3469989

0

Please sign in to leave a comment.