Rename fields and properties

I'm working on some ORM mapping classes generated by MyGeneration and I noticed the rename field/property isn't working correctly. As an example, I have an interface and a concrete class with the following:

public Interface X
{
string OrderNo { get; set; }
}

public class Y
{
private string _OrderNo;

public string OrderNo
{
get { return _OrderNo; }
set { _OrderNo = value; }
}
}

I want to change these to OrderNumber and _orderNumber respectively, so I right click on the property in the interface, select Rename, and type OrderNumber. The oddity is that it asks me to rename the property _OrderNumber instead of _orderNumber. If I try to rename the field to _orderNumber, it asks me to rename the property to _OrderNumber instead of OrderNumber. In either case, the behavior is odd and inconsistent.

So... can I somehow either make this work the way I want or globally disable renaming related objects? As it is I have to rename the fields, uncheck the box to rename the property, rename the property, uncheck the box to rename the field, and fix the mapping in the XML file.

4 comments
Comment actions Permalink

I just discovered another odd case in which I tried to fix the casing of the orderdate field. In this case, I renamed the field to _orderDate and it asked me to rename the property to Date (completely dropping the first word).

"Lothan" <lothan@newsguy.com> wrote in message news:eg9ebu$hg2$1@is.intellij.net...
I'm working on some ORM mapping classes generated by MyGeneration and I noticed the rename field/property isn't working correctly. As an example, I have an interface and a concrete class with the following:

public Interface X
{
string OrderNo { get; set; }
}

public class Y
{
private string _OrderNo;

public string OrderNo
{
get { return _OrderNo; }
set { _OrderNo = value; }
}
}

I want to change these to OrderNumber and _orderNumber respectively, so I right click on the property in the interface, select Rename, and type OrderNumber. The oddity is that it asks me to rename the property _OrderNumber instead of _orderNumber. If I try to rename the field to _orderNumber, it asks me to rename the property to _OrderNumber instead of OrderNumber. In either case, the behavior is odd and inconsistent.

So... can I somehow either make this work the way I want or globally disable renaming related objects? As it is I have to rename the fields, uncheck the box to rename the property, rename the property, uncheck the box to rename the field, and fix the mapping in the XML file.

0
Comment actions Permalink

Hello Lothan,

Did you setup field prefix in ReSharper options? Otherwise ReSharper will
not know that "_" is not part of the name and just field prefix. Open ReSharper
Options, Code style, Naming conventions page, put "_" in the Name prefix
field for instance fields and check if rename will work correctly.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


L> I just discovered another odd case in which I tried to fix the casing
L> of the orderdate field. In this case, I renamed the field to
L> _orderDate and it asked me to rename the property to Date (completely
L> dropping the first word).
L>
L> "Lothan" <lothan@newsguy.com> wrote in message
L> news:eg9ebu$hg2$1@is.intellij.net...
L> I'm working on some ORM mapping classes generated by MyGeneration
L> and I noticed the rename field/property isn't working correctly. As
L> an example, I have an interface and a concrete class with the
L> following:
L> public Interface X
L> {
L> string OrderNo { get; set; }
L> }
L> public class Y
L> {
L> private string _OrderNo;
L> public string OrderNo
L> {
L> get { return _OrderNo; }
L> set { _OrderNo = value; }
L> }
L> }
L> I want to change these to OrderNumber and _orderNumber
L> respectively, so I right click on the property in the interface,
L> select Rename, and type OrderNumber. The oddity is that it asks me to
L> rename the property _OrderNumber instead of _orderNumber. If I try to
L> rename the field to _orderNumber, it asks me to rename the property
L> to _OrderNumber instead of OrderNumber. In either case, the behavior
L> is odd and inconsistent.
L>
L> So... can I somehow either make this work the way I want or
L> globally disable renaming related objects? As it is I have to rename
L> the fields, uncheck the box to rename the property, rename the
L> property, uncheck the box to rename the field, and fix the mapping in
L> the XML file.
L>


0
Comment actions Permalink

Yes, I have the field prefix set to "_" (without the quotes) but it has
never really worked well. At one point, it worked if I renamed the property
but presented odd results if I renamed the field. Somewhere around 260 I
started seeing odd results either way.

I just noticed the recommended names in 263 aren't working as well as they
did in 260. I have one class in which I have a variable named date. When I
try to type something like date = DateTime.ParseExact(...), it overlooks the
variable name and I end up with DateTime = ...

--


"Ilya Ryzhenkov" <orangy@netix.ru> wrote in message
news:9f6b3e2912b6e28c8b8fa656f5b2c@news.jetbrains.com...

Hello Lothan,

>

Did you setup field prefix in ReSharper options? Otherwise ReSharper will
not know that "_" is not part of the name and just field prefix. Open
ReSharper Options, Code style, Naming conventions page, put "_" in the
Name prefix field for instance fields and check if rename will work
correctly.
Sincerely,
Ilya Ryzhenkov

>

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>
>

L> I just discovered another odd case in which I tried to fix the casing
L> of the orderdate field. In this case, I renamed the field to
L> _orderDate and it asked me to rename the property to Date (completely
L> dropping the first word).
L> L> "Lothan" <lothan@newsguy.com> wrote in message
L> news:eg9ebu$hg2$1@is.intellij.net...
L> I'm working on some ORM mapping classes generated by MyGeneration
L> and I noticed the rename field/property isn't working correctly. As
L> an example, I have an interface and a concrete class with the
L> following:
L> public Interface X
L> {
L> string OrderNo { get; set; }
L> }
L> public class Y
L> {
L> private string _OrderNo;
L> public string OrderNo
L> {
L> get { return _OrderNo; }
L> set { _OrderNo = value; }
L> }
L> }
L> I want to change these to OrderNumber and _orderNumber
L> respectively, so I right click on the property in the interface,
L> select Rename, and type OrderNumber. The oddity is that it asks me to
L> rename the property _OrderNumber instead of _orderNumber. If I try to
L> rename the field to _orderNumber, it asks me to rename the property
L> to _OrderNumber instead of OrderNumber. In either case, the behavior
L> is odd and inconsistent.
L> L> So... can I somehow either make this work the way I want or
L> globally disable renaming related objects? As it is I have to rename
L> the fields, uncheck the box to rename the property, rename the
L> property, uncheck the box to rename the field, and fix the mapping in
L> the XML file.
L>



0
Comment actions Permalink

I just submitted a bug in JIRA regarding this issue in Build 265. The
behavior is dramatically changed in Build 265 and results in some absolutely
bizarre names that are mixtures of the old name and the new name. I also
found one case that caused ReSharper to crash. The crash report is in JIRA.
Create a field named _ABC123 and property named ABC123 that gets/sets
_ABC123. Rename _ABC123 to something. ReSharper will attempt to name the
property 123 and crash reliably. The stack trace is in ticket 30222.

Renaming fields with matching property accessors does not work correctly.
I'm working with a class generated by MyGeneration in which I need to rename
the fields to match our naming conventions (leading underscore and camel
case) and to "correctly" name some of field names in the database. There are
four general cases.

1. The field and property accessor contain one word:

private int _Word;
public int Word { get; set; }

Select Rename on _Word. ReSharper recommends _word and does not prompt to
rename the Word property since its name already matches. This one actually
works as expected.

2. The field and property accessor contain two words and are renamed to
correct the case:

private int _DoubleWord;
public int DoubleWord { get; set; }

Select Rename on _DoubleWord. ReSharper recommends _doubleWord, but prompts
to rename the DoubleWord property to Word. It should keep DoubleWord to
match the field name. In this case, ReSharper drops the first word entirely.

3. The field and property accessor contain two words and renamed to
different words:

private int _someName;
public int SomeName { get; set; }

Rename _someName to _totallyDifferent. ReSharper recommends renaming the
property accessor to SomeDifferent, which is the first word of the original
name and second word of the new name so you get this:

private int _totallyDifferent;
public int SomeDifferent { get; set; }

4. The field and property accessor contain two words in all caps:

private int CAPSWord;
public int CAPS_Word { get; set; }

Select Rename on CAPSWord. Override the recommended default to name the
field _anotherName and click Continue. ReSharper now prompts to rename the
property accessor to NAMEWord. Note that NAME is the second word in the new
name capitalized to match the first word in the original name, and Word is
the second word in the original name.

As another example:

private int XYZSomething;
public int XYZ_Something { get; set; }

Rename the field to _totallyDifferent:

private int _totallyDifferent;
public int DIFFERENTSomething { get; set; }

I discovered another after posting the above in JIRA. Rename a field that
contains only all caps (_ABC) to something without all caps, and ReSharper
doesn't even prompt to rename the property. When I tried to rename _ABC123,
ReSharper crashed.


"Ilya Ryzhenkov" <orangy@netix.ru> wrote in message
news:9f6b3e2912b6e28c8b8fa656f5b2c@news.jetbrains.com...

Hello Lothan,

>

Did you setup field prefix in ReSharper options? Otherwise ReSharper will
not know that "_" is not part of the name and just field prefix. Open
ReSharper Options, Code style, Naming conventions page, put "_" in the
Name prefix field for instance fields and check if rename will work
correctly.
Sincerely,
Ilya Ryzhenkov

>

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>
>

L> I just discovered another odd case in which I tried to fix the casing
L> of the orderdate field. In this case, I renamed the field to
L> _orderDate and it asked me to rename the property to Date (completely
L> dropping the first word).
L> L> "Lothan" <lothan@newsguy.com> wrote in message
L> news:eg9ebu$hg2$1@is.intellij.net...
L> I'm working on some ORM mapping classes generated by MyGeneration
L> and I noticed the rename field/property isn't working correctly. As
L> an example, I have an interface and a concrete class with the
L> following:
L> public Interface X
L> {
L> string OrderNo { get; set; }
L> }
L> public class Y
L> {
L> private string _OrderNo;
L> public string OrderNo
L> {
L> get { return _OrderNo; }
L> set { _OrderNo = value; }
L> }
L> }
L> I want to change these to OrderNumber and _orderNumber
L> respectively, so I right click on the property in the interface,
L> select Rename, and type OrderNumber. The oddity is that it asks me to
L> rename the property _OrderNumber instead of _orderNumber. If I try to
L> rename the field to _orderNumber, it asks me to rename the property
L> to _OrderNumber instead of OrderNumber. In either case, the behavior
L> is odd and inconsistent.
L> L> So... can I somehow either make this work the way I want or
L> globally disable renaming related objects? As it is I have to rename
L> the fields, uncheck the box to rename the property, rename the
L> property, uncheck the box to rename the field, and fix the mapping in
L> the XML file.
L>



0

Please sign in to leave a comment.