Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Visual Studio perform refactoring on views/pages as well?

Suppose I have a model and a view that display this model properties.

public class UserModel
{
    public string UserName { get; set; }
    .................
}

somewhere in a view...

<%= Model.UserName %>

Now I rename one of the properties (say, UserName => FullUserName), VS will suggest to perform refactoring meaning project-wide renaming of references to this property. It will really work everywhere in code except in the views.

Why? There is a setting to have the views compiled at the project build. Why won't it perform simple little refactoring there as well?

Is there any way to persuade it to?

like image 697
User Avatar asked Nov 06 '22 20:11

User


1 Answers

ReSharper supports renaming like this and also provides support for optionally renaming string literals. This is useful if you have code like this:

<asp:Label id="label1" runat="server"
     Text='<%# Container.DataItem("CustomerName") %>

If you rename the CustomerName property then ReSharper will prompt to see if you would like to change the "CustomerName" string too.

ReSharper isn't free but it is a very powerful tool and it can do a lot more than refactoring.

like image 58
MikeD Avatar answered Nov 15 '22 00:11

MikeD