You can use Visual Studio's Quick Actions (Light Bulb) feature to refactor your code. See the Related information for more details.