This Question is Answered

2 "helpful" answers available (2 pts)
7 Replies Last post: Aug 12, 2010 8:47 PM by Matt Mills  
Nicholas Cloud Newbie 4 posts since
Jul 29, 2010
Currently Being Moderated

Jul 29, 2010 7:37 PM

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?

Andrey Serebryansky JetBrains 2,900 posts since
Jan 12, 2005
Currently Being Moderated
Jul 30, 2010 1:15 PM in response to: Nicholas Cloud
Re: use auto-property in code cleanup not working?

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

 

 

 

Leslie Hill Newbie 1 posts since
Jun 6, 2009
Currently Being Moderated
Aug 2, 2010 8:54 PM in response to: Nicholas Cloud
Re: use auto-property in code cleanup not working?

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.

Matt Mills Newbie 2 posts since
Aug 12, 2010
Currently Being Moderated
Aug 12, 2010 7:19 PM in response to: Nicholas Cloud
Re: use auto-property in code cleanup not working?

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.

Andrey Serebryansky JetBrains 2,900 posts since
Jan 12, 2005
Currently Being Moderated
Aug 12, 2010 8:29 PM in response to: Matt Mills
Re: use auto-property in code cleanup not working?

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

{

Serializable

public class Class1

{

private bool _wontChange;

public bool WontChange

{

get { return _wontChange; }

set { _wontChange = value; }

}

}

}

 

 

 

Matt Mills Newbie 2 posts since
Aug 12, 2010
Currently Being Moderated
Aug 12, 2010 8:47 PM in response to: Andrey Serebryansky
Re: use auto-property in code cleanup not working?

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

More Like This

  • Retrieving data ...