Gives a symbol a new name and updates every reference to it across the solution.
Precondition
The new name is a C# identifier. A keyword is only accepted escaped with @. The rename leaves the solution compiling: the new name does not clash with a member, local or type already declared where the symbol is. When the symbol is a top-level type whose file is named after it, no file with the new name already exists beside it.
The declaration and every reference are renamed, in every project that sees the symbol: calls, member accesses, object initializers, named arguments, nameof and <see cref="..."/> in documentation comments. Renaming a virtual or abstract member renames its overrides and base calls; renaming an interface member renames its implicit and explicit implementations. Renaming any of them renames the whole family. Renaming a type renames its constructors. Renaming a generic type renames its constructed uses. Renaming a namespace renames its last part in declarations, using directives and qualified names. A top-level type declared in a file named after it, such as Customer.cs for Customer, has that file renamed to match. A file named after something else keeps its name. A reference the rename would capture, such as a call that an existing overload with the new name would bind to, is kept on the renamed symbol by casting or qualifying it.
Preserved
What every reference refers to. Comments, blank lines and layout: only the identifiers change.
Limitations
Strings and comments other than documentation references are not searched, so a name written in a string literal or a plain comment keeps the old name. Partial types split across files named Order.cs and Order.Lines.cs have only the file named exactly after the type renamed.
Error codes
Code Meaning name-conflictthe new name clashes with existing code, so the result would not compile invalid-namethe new name is not a C# identifier file-existsthe type's file would be renamed onto a file that already exists
Cases
Expand all · Collapse all
Diffs show each file from before to after .
/*[*/ … /*]*/ marks a selection and /*^*/ a caret; the runner removes them before the refactoring runs.
# across-projectsRenames a public method and its calls in a project that references the declaring one
success
Target symbol M:Core.Catalog.Find(System.String)
Projects Core; App → Core
App/Program.cs modified
1 1 using Core ;2 2 3 3 namespace App 4 4 { 5 5 public class Program 6 6 { 7 − public string Run (Catalog catalog) => catalog.Find ("A1" ); 7 + public string Run (Catalog catalog) => catalog.Lookup ("A1" ); 8 8 } 9 9 }
Core/Catalog.cs modified
1 1 namespace Core 2 2 { 3 3 public class Catalog 4 4 { 5 − public string Find (string sku) => sku; 5 + public string Lookup (string sku) => sku; 6 6 } 7 7 }
View fixture on GitHub
# conflicting-member-refusedRefuses to give a method the name and signature of another member of its class
refusal
Target symbol M:Shop.Cart.Add(System.Int32)
Refuses name-conflict; every file is left unchanged
Cart.cs input
1 namespace Shop 2 { 3 public class Cart 4 { 5 private int _count; 6 7 public void Add (int quantity) => _count += quantity; 8 9 public void Remove (int quantity) => _count -= quantity; 10 } 11 }
View fixture on GitHub
# file-exists-refusedRefuses to rename a type when the file it would be renamed to already exists
refusal
Target symbol T:Shop.Customer
Refuses file-exists; every file is left unchanged
Client.cs input
1 namespace Shop 2 { 3 public class ClientFactory 4 { 5 public Customer Create () => new Customer (); 6 } 7 }
Customer.cs input
1 namespace Shop 2 { 3 public class Customer 4 { 5 } 6 }
View fixture on GitHub
# generic-typeRenames a generic class and its constructed uses, and renames its file
success
Target symbol T:Shop.Box`1
Box.cs deleted
1 − namespace Shop 2 − { 3 − public class Box <T > 4 − { 5 − public Box (T item) => Item = item; 6 − 7 − public T Item { get ; } 8 − 9 − public Box <T > Copy () => new Box <T >(Item ); 10 − } 11 − }
Container.cs added
1 + namespace Shop 2 + { 3 + public class Container <T > 4 + { 5 + public Container (T item) => Item = item; 6 + 7 + public T Item { get ; } 8 + 9 + public Container <T > Copy () => new Container <T >(Item ); 10 + } 11 + }
Shelf.cs modified
1 1 using System .Collections .Generic ;2 2 3 3 namespace Shop 4 4 { 5 5 public class Shelf 6 6 { 7 − private readonly List <Box <int >> _boxes = new List <Box <int >>(); 7 + private readonly List <Container <int >> _boxes = new List <Container <int >>(); 8 8 9 − public void Add (int item) => _boxes.Add (new Box <int >(item)); 9 + public void Add (int item) => _boxes.Add (new Container <int >(item)); 10 10 } 11 11 }
View fixture on GitHub
# interface-method-and-implementationsRenames an interface method with its implicit and explicit implementations and the calls through each
success
Target symbol M:Shop.INotifier.Send(System.String)
INotifier.cs modified
1 1 namespace Shop 2 2 { 3 3 public interface INotifier 4 4 { 5 − void Send (string message); 5 + void Notify (string message); 6 6 } 7 7 }
Notifiers.cs modified
1 1 namespace Shop 2 2 { 3 3 public class EmailNotifier : INotifier 4 4 { 5 − public void Send (string message) 5 + public void Notify (string message) 6 6 { 7 7 } 8 8 } 9 9 10 10 public class SmsNotifier : INotifier 11 11 { 12 − void INotifier .Send (string message) 12 + void INotifier .Notify (string message) 13 13 { 14 14 } 15 15 } 16 16 17 17 public class Alerts 18 18 { 19 19 public void Raise (INotifier notifier, EmailNotifier email) 20 20 { 21 − notifier.Send ("down" ); 22 − email.Send ("down" ); 21 + notifier.Notify ("down" ); 22 + email.Notify ("down" ); 23 23 } 24 24 } 25 25 }
View fixture on GitHub
# invalid-name-refusedRefuses a new name that is not a C# identifier
refusal
Target symbol M:Shop.Order.Total
Refuses invalid-name; every file is left unchanged
Order.cs input
1 namespace Shop 2 { 3 public class Order 4 { 5 public int Total () => 10 ; 6 } 7 }
View fixture on GitHub
# local-at-caretRenames a local variable chosen by caret, and every use of it
success
Target Sample.cs, the /*^*/ caret
Sample.cs modified
1 1 public class Sample 2 2 { 3 3 public int Sum (int a, int b) 4 4 { 5 − var /*^*/ x = a + b; 6 − return x * 2 ; 5 + var total = a + b; 6 + return total * 2 ; 7 7 } 8 8 }
View fixture on GitHub
# local-conflict-refusedRefuses to give a local the name of another local in the same scope
refusal
Target Sample.cs, the /*^*/ caret
Refuses name-conflict; every file is left unchanged
Sample.cs input
1 public class Sample 2 { 3 public int Sum (int a, int b) 4 { 5 var total = a; 6 var /*^*/ x = b; 7 return total + x; 8 } 9 }
View fixture on GitHub
# method-across-filesRenames one overload of a method and its calls in another file, leaving the other overload alone
success
Target symbol M:Shop.Order.Total(System.Int32)
Checkout.cs modified
1 1 namespace Shop 2 2 { 3 3 public class Checkout 4 4 { 5 − public int Pay (Order order) => order.Total (2 ) + order.Total (); 5 + public int Pay (Order order) => order.TotalWithDiscount (2 ) + order.Total (); 6 6 } 7 7 }
Order.cs modified
1 1 namespace Shop 2 2 { 3 3 public class Order 4 4 { 5 5 public int Total () => 10 ; 6 6 7 − public int Total (int discount) => Total () - discount; 7 + public int TotalWithDiscount (int discount) => Total () - discount; 8 8 } 9 9 }
View fixture on GitHub
# namespaceRenames the last part of a namespace in its declaration, using directives and qualified names
success
Target symbol N:Shop.Billing
Invoice.cs modified
1 − namespace Shop .Billing 1 + namespace Shop .Payments 2 2 { 3 3 public class Invoice 4 4 { 5 5 public decimal Amount { get ; set ; } 6 6 } 7 7 }
Order.cs modified
1 − using Shop .Billing ;1 + using Shop .Payments ;2 2 3 3 namespace Shop 4 4 { 5 5 public class Order 6 6 { 7 7 public Invoice Bill () => new Invoice (); 8 8 9 − public Shop .Billing .Invoice Refund () => new Shop .Billing .Invoice (); 9 + public Shop .Payments .Invoice Refund () => new Shop .Payments .Invoice (); 10 10 } 11 11 }
View fixture on GitHub
# nullable-propertyRenames a nullable property, including its use in an object initializer and a null-conditional access in another file
success
Target symbol P:Shop.Customer.Nickname
Project nullable enable
Customer.cs modified
1 1 namespace Shop 2 2 { 3 3 public class Customer 4 4 { 5 − public string ? Nickname { get ; set ; } 5 + public string ? DisplayName { get ; set ; } 6 6 } 7 7 }
Greeter.cs modified
1 1 namespace Shop 2 2 { 3 3 public class Greeter 4 4 { 5 − public Customer Create () => new Customer { Nickname = "Ada" }; 5 + public Customer Create () => new Customer { DisplayName = "Ada" }; 6 6 7 − public int Length (Customer customer) => customer.Nickname ?.Length ?? 0 ; 7 + public int Length (Customer customer) => customer.DisplayName ?.Length ?? 0 ; 8 8 } 9 9 }
View fixture on GitHub
# overload-kept-by-castGives a method the name of an existing overload, casting an argument where the call would otherwise bind to that overload
success
Target symbol M:Shop.Printer.Print(System.Object)
Printer.cs modified
1 1 namespace Shop 2 2 { 3 3 public class Printer 4 4 { 5 − public string Print (object value ) => "object" ; 5 + public string Show (object value ) => "object" ; 6 6 7 7 public string Show (string value ) => "string" ; 8 8 9 − public string Run () => Print ("text" ); 9 + public string Run () => Show ((object )"text" ); 10 10 } 11 11 }
View fixture on GitHub
# parameter-with-named-argumentsRenames a parameter chosen by caret, its uses in the body and the named arguments that pass it in another file
success
Target Pricing.cs, the /*^*/ caret
Checkout.cs modified
1 1 namespace Shop 2 2 { 3 3 public class Checkout 4 4 { 5 5 public decimal Total (decimal amount) => 6 − Pricing .Apply (amount, factor: 0.9m ) + Pricing .Apply (factor: 2m , amount: amount); 6 + Pricing .Apply (amount, rate: 0.9m ) + Pricing .Apply (rate: 2m , amount: amount); 7 7 } 8 8 }
Pricing.cs modified
1 1 namespace Shop 2 2 { 3 3 public static class Pricing 4 4 { 5 − public static decimal Apply (decimal amount, decimal /*^*/ factor = 1m ) 5 + public static decimal Apply (decimal amount, decimal rate = 1m ) 6 6 { 7 − return amount * factor; 7 + return amount * rate; 8 8 } 9 9 } 10 10 }
View fixture on GitHub
# type-and-its-fileRenames a class, its constructor and every use of it, and renames the file named after it
success
Target symbol T:Shop.Customer
Client.cs added
1 + namespace Shop 2 + { 3 + public class Client 4 + { 5 + public Client (string name) 6 + { 7 + Name = name; 8 + } 9 + 10 + public string Name { get ; } 11 + } 12 + }
Customer.cs deleted
1 − namespace Shop 2 − { 3 − public class Customer 4 − { 5 − public Customer (string name) 6 − { 7 − Name = name; 8 − } 9 − 10 − public string Name { get ; } 11 − } 12 − }
Order.cs modified
1 1 namespace Shop 2 2 { 3 3 public class Order 4 4 { 5 − private readonly Customer _customer = new Customer ("Ada" ); 5 + private readonly Client _customer = new Client ("Ada" ); 6 6 7 − public Customer Buyer => _customer; 7 + public Client Buyer => _customer; 8 8 } 9 9 }
View fixture on GitHub
# type-in-shared-fileRenames a class declared in a file named after something else, leaving the file name alone
success
Target symbol T:Shop.Address
Models.cs modified
1 1 namespace Shop 2 2 { 3 3 public class Customer 4 4 { 5 − public Address Home { get ; set ; } = new Address (); 5 + public Location Home { get ; set ; } = new Location (); 6 6 } 7 7 8 − public class Address 8 + public class Location 9 9 { 10 10 public string Street { get ; set ; } = "" ; 11 11 } 12 12 }
View fixture on GitHub
# virtual-method-and-overridesRenames a virtual method together with its override, the base call and the calls through either type
success
Target symbol M:Shop.Shape.Area
Report.cs modified
1 1 namespace Shop 2 2 { 3 3 public class Report 4 4 { 5 − public double Sum (Shape shape, Square square) => shape.Area () + square.Area (); 5 + public double Sum (Shape shape, Square square) => shape.Surface () + square.Surface (); 6 6 } 7 7 }
Shapes.cs modified
1 1 namespace Shop 2 2 { 3 3 public class Shape 4 4 { 5 − public virtual double Area () => 0 ; 5 + public virtual double Surface () => 0 ; 6 6 } 7 7 8 8 public class Square : Shape 9 9 { 10 10 public double Side { get ; set ; } 11 11 12 − public override double Area () => base .Area () + Side * Side ; 12 + public override double Surface () => base .Surface () + Side * Side ; 13 13 } 14 14 }
View fixture on GitHub