Hi,
I currently have "Make Properties auto-implemented" turn ON. turning the option off doesn't have the issue.
Given this class:
C#public class Class2
{
private TreeDataCollectionBase m_Collection;
public TreeDataCollectionBase Collection
{
get
{
return m_Collection;
}
}
public void DeleteNode(string key)
{
m_Collection.Remove(key);
}
public void PopulateTreeNodes()
{
m_Collection.Sort();
this.Collection.Sort();
}
}
You can see that the "m_Collection" variable has the Remove() and Sort() methods on it in the two methods at the bottom of the class, (Note I've added a 2nd call to the sort method to explain another issue below. When I run code clean up with the option mentioned above turned ON, the code looks like this:
C#public class Class2
{
public TreeDataCollectionBase Collection { get; private set; }
public void DeleteNode(string key) => this.Collection(key);
public void PopulateTreeNodes()
{
this.Collection();
Collection.Sort();
}
}
As you can see, the "m_collection" variable has gone (which is what I want) the two lines in the methods (DeleteNode & PopulateTreeNode) are now missing the calls to the Remove() and Sort() methods. I've bold the section where it should have the calls.
Also I have it set to remove the "THIS" part as well as it just clutters the code, but no matter how many times I press clean up, it's not removed from these two lines (but generally is) the word "this" is not faded in the above two cases. I've added in the first example the "this.Collection.Sort()" line to show that "this" is removed when done like this initially.
Hope this helps.
Alan
I've just been playing around with the order of the code cleanup rules and noticed if I move "Use Expression Bodies" ABOVE the "Make properties auto-implemented" (both turned ON) then nothing happens with the auto-implemented option…
If I then clean up, and move the Use Expression bodies BELOW then again, nothing happens (maybe because we have expression bodies now).
Hope this helps.
Hi Alan,
Thank you for letting us know about this problem and providing the code samples. They helped me reproduce the problem. We are working on the solution and you will be notified when we prepare a fix.
Also, note that the code cleanup rules are applied in the same order as they are present in the list on the options page. Since a property can't have an expression body but be auto-Implemented simultaneously, the "Use Expression Body" and "Convert to Auto-Implemented Property" rules are mutually exclusive. Either the "Use Expression Body" and "Convert to Auto-Implemented Property" rule will be applied depending on their order in the "Rules" list.
Glad it helped, I understand the order is important, If Expression body is above auto implemented then it won't change the m_collection variable in the example, which is fine. but in my case I actually have the order the other way around, so I want the m_collection variable to be auto implemented, and THEN the rest of the properties to be expression bodies :)
Alan,
Thank you for the update.
In your case, I recommend you to keep one code style option for code cleanup, which you prefer to use in most cases ("Use Expression Bodies"). This will allow you to apply this property style in the batch manner (apply to multiple properties at the same time). And if you want to apply the different style for the particular property (e.g. Auto-Implemented), I recommend you use the Quick Action menu (Ctrl + . or Ctrl + ~) and execute the appropriate action.
This makes sense to do and the expression bodies is the best one to have on, but I've always had the two options turned on and not had a problem before so I think this is a new bug recently introduced - looking at the screen shot you provided the difference screen (red/green lines) even shows the .Remove() and .Sort() method calls removed.
Once it's been fixed I'll retest and see how it goes. Thanks.
Alan,
Thank you for the update.
We are working on a fix for the problem with unexpected removing of .Remove() and .Sort() method calls. We will update this ticket when the solution is ready.