Makes calls that pass a constant for a parameter call, directly, the method the original runs for that value. When SetValue(string name, int value) calls SetHeight(value) for "height", box.SetValue("height", 10) becomes box.SetHeight(10). Replace Parameter with Explicit Methods uses it once the branches have methods of their own.
Target
The method whose calls are redirected, by symbol, with:
Argument Meaning parameterthe parameter the calls pass the constant for valuethe constant, written as C#, such as "\"height\"" or "Zone.Europe" methodthe method the original calls for that value
Precondition
The target is an ordinary, non-generic method with a block body. It is not virtual, abstract, an override or an interface implementation, so a call of it runs its body. The value is a constant of the parameter's type. The class has a method with the given name. With the parameter holding the value, the method does nothing but call that method and return what it returns. Following the value from the start of the body through if statements that compare the parameter with constants using built-in == or !=, else branches and switch statements on the parameter with constant case labels, the statements reached are return M(...);, or for a void method M(...); return;, or M(...); as the method's last statement. That call has no receiver or this, and passes some of the method's own parameters unchanged, in any order, each to a parameter of the same type and without ref, out, in or params. For a method returning a value, M returns the same type. The redirected calls compile, so the method is accessible wherever a call is.
Each call of the method, in any file or project, whose argument for the parameter is a constant equal to the value becomes a call of the named method on the same receiver, passing the call's arguments for the parameters the method passes on, in its order. The arguments keep their comments. A named argument keeps its name, changed to the name of the parameter it now goes to. Calls passing another value or a variable, and calls of other overloads, are left alone.
Preserved
What each redirected call does: it runs the call the method would have made for the value, with the same argument values. The order arguments are evaluated in. A call is left alone when it would drop, repeat or reorder an argument that is anything but a constant, a local, a parameter, this or a field of this object, since that argument would no longer be evaluated as it was.
Limitations
A call that leaves out an optional argument, passes a params array in expanded form, or passes an argument by reference is left alone. A call where the named method would bind to another method, such as one a derived class hides it with, is left alone. A dispatch that compares the parameter in any other way, such as with Equals, patterns or combined conditions, ends the walk, and the method is refused as doing more than the call. The original method stays, even when no call of it is left.
Error codes
Code Meaning not-a-methodthe target is not an ordinary method with a block body polymorphic-methodthe method is virtual, an override or an interface implementation generic-methodthe method is generic unknown-parameterthe method has no parameter of that name not-a-constantthe value is not a constant of the parameter's type unknown-methodthe class has no method of the given name does-more-than-callfor the value, the method does more than call the named method with its parameters does-not-compilea redirected call would not compile, such as when the named method is not accessible there
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-projectsA call in a project that references the method's project is redirected
success
Target symbol M:Shapes.Box.SetValue(System.String,System.Int32)
Arguments parameter"name"value"\"height\""method"SetHeight"
Projects Core; App → Core
App/Builder.cs modified
1 1 namespace Shapes 2 2 { 3 3 public class Builder 4 4 { 5 5 public Box Build (string dimension, int size) 6 6 { 7 7 var box = new Box (); 8 − box.SetValue ("height" , 10 ); 8 + box.SetHeight (10 ); 9 9 box.SetValue ("width" , size * 2 ); 10 10 box.SetValue (dimension, size); 11 11 return box; 12 12 } 13 13 } 14 14 }
Core/Box.cs unchanged
1 1 using System ;2 2 3 3 namespace Shapes 4 4 { 5 5 public class Box 6 6 { 7 7 private int _height; 8 8 private int _width; 9 9 10 10 public void SetValue (string name, int value ) 11 11 { 12 12 if (name == "height" ) 13 13 { 14 14 SetHeight (value ); 15 15 return ; 16 16 } 17 17 if (name == "width" ) 18 18 { 19 19 SetWidth (value ); 20 20 return ; 21 21 } 22 22 throw new ArgumentException ("Unknown dimension " + name); 23 23 } 24 24 25 25 public void SetHeight (int value ) 26 26 { 27 27 _height = value ; 28 28 } 29 29 30 30 public void SetWidth (int value ) 31 31 { 32 32 _width = value ; 33 33 } 34 34 35 35 public int Area () 36 36 { 37 37 return _height * _width; 38 38 } 39 39 } 40 40 }
View fixture on GitHub
# call-formsA call inside the class with no receiver, a conditional call with named arguments, and a call on a new object are each redirected, keeping the receiver and the names of the arguments that remain
success
Target symbol M:Shapes.Box.SetValue(System.String,System.Int32)
Arguments parameter"name"value"\"height\""method"SetHeight"
Box.cs modified
1 1 using System ;2 2 3 3 namespace Shapes 4 4 { 5 5 public class Box 6 6 { 7 7 private int _height; 8 8 private int _width; 9 9 10 10 public void SetValue (string name, int value ) 11 11 { 12 12 if (name == "height" ) 13 13 { 14 14 SetHeight (value ); 15 15 return ; 16 16 } 17 17 if (name == "width" ) 18 18 { 19 19 SetWidth (value ); 20 20 return ; 21 21 } 22 22 throw new ArgumentException ("Unknown dimension " + name); 23 23 } 24 24 25 25 public void SetHeight (int value ) 26 26 { 27 27 _height = value ; 28 28 } 29 29 30 30 public void SetWidth (int value ) 31 31 { 32 32 _width = value ; 33 33 } 34 34 35 35 public void Flatten () 36 36 { 37 − SetValue ("height" , 0 ); 37 + SetHeight (0 ); 38 38 } 39 39 40 40 public int Area () 41 41 { 42 42 return _height * _width; 43 43 } 44 44 } 45 45 }
Builder.cs modified
1 1 namespace Shapes 2 2 { 3 3 public class Builder 4 4 { 5 5 public Box Build (Box box) 6 6 { 7 − box?.SetValue (value : 3 , name: "height" ); 8 − new Box ().SetValue ("height" , 4 ); 7 + box?.SetHeight (value : 3 ); 8 + new Box ().SetHeight (4 ); 9 9 return box; 10 10 } 11 11 } 12 12 }
View fixture on GitHub
# does-more-than-call-rejectedRefuses when the branch for the value does more than call the named method, since the call would skip the rest
refusal
Target symbol M:Shapes.Box.SetValue(System.String,System.Int32)
Arguments parameter"name"value"\"height\""method"SetHeight"
Refuses does-more-than-call; every file is left unchanged
Box.cs input
1 using System ;2 3 namespace Shapes 4 { 5 public class Box 6 { 7 private int _height; 8 private int _width; 9 10 public void SetValue (string name, int value ) 11 { 12 if (name == "height" ) 13 { 14 SetHeight (value ); 15 _width = value ; 16 return ; 17 } 18 if (name == "width" ) 19 { 20 SetWidth (value ); 21 return ; 22 } 23 throw new ArgumentException ("Unknown dimension " + name); 24 } 25 26 public void SetHeight (int value ) 27 { 28 _height = value ; 29 } 30 31 public void SetWidth (int value ) 32 { 33 _width = value ; 34 } 35 36 public int Area () 37 { 38 return _height * _width; 39 } 40 } 41 }
Builder.cs input
1 namespace Shapes 2 { 3 public class Builder 4 { 5 public Box Build (string dimension, int size) 6 { 7 var box = new Box (); 8 box.SetValue ("height" , 10 ); 9 box.SetValue ("width" , size * 2 ); 10 box.SetValue (dimension, size); 11 return box; 12 } 13 } 14 }
View fixture on GitHub
# expression-bodied-rejectedRefuses a method without a block body, which has no dispatch to follow
refusal
Target symbol M:Shapes.Box.SetValue(System.String,System.Int32)
Arguments parameter"name"value"\"height\""method"SetHeight"
Refuses not-a-method; every file is left unchanged
Box.cs input
1 using System ;2 3 namespace Shapes 4 { 5 public class Box 6 { 7 private int _height; 8 private int _width; 9 10 public void SetValue (string name, int value ) => SetHeight (name == "height" ? value : throw new ArgumentException (name)); 11 12 public void SetHeight (int value ) 13 { 14 _height = value ; 15 } 16 17 public void SetWidth (int value ) 18 { 19 _width = value ; 20 } 21 22 public int Area () 23 { 24 return _height * _width; 25 } 26 } 27 }
Builder.cs input
1 namespace Shapes 2 { 3 public class Builder 4 { 5 public Box Build (string dimension, int size) 6 { 7 var box = new Box (); 8 box.SetValue ("height" , 10 ); 9 box.SetValue ("width" , size * 2 ); 10 box.SetValue (dimension, size); 11 return box; 12 } 13 } 14 }
View fixture on GitHub
# generic-classA method of a generic class dispatching with a switch whose sections break; a call on a constructed type calls the named method on it
success
Target symbol M:Config.Setting`1.Set(System.String,`0)
Arguments parameter"key"value"\"name\""method"SetName"
Profile.cs modified
1 1 namespace Config 2 2 { 3 3 public class Profile 4 4 { 5 5 public Setting <string > Create () 6 6 { 7 7 var setting = new Setting <string >(); 8 − setting.Set ("name" , "Ada" ); 8 + setting.SetName ("Ada" ); 9 9 setting.Set ("title" , "Countess" ); 10 10 return setting; 11 11 } 12 12 } 13 13 }
Setting.cs unchanged
1 1 namespace Config 2 2 { 3 3 public class Setting <T > 4 4 { 5 5 public T Name { get ; private set ; } 6 6 7 7 public T Title { get ; private set ; } 8 8 9 9 public void Set (string key, T value ) 10 10 { 11 11 switch (key) 12 12 { 13 13 case "name" : 14 14 SetName (value ); 15 15 break ; 16 16 case "title" : 17 17 SetTitle (value ); 18 18 break ; 19 19 } 20 20 } 21 21 22 22 public void SetName (T value ) 23 23 { 24 24 Name = value ; 25 25 } 26 26 27 27 public void SetTitle (T value ) 28 28 { 29 29 Title = value ; 30 30 } 31 31 } 32 32 }
View fixture on GitHub
# generic-method-rejectedRefuses a generic method, whose type arguments the named method would not take
refusal
Target symbol M:Shapes.Box.SetValue``1(System.String,System.Int32)
Arguments parameter"name"value"\"height\""method"SetHeight"
Refuses generic-method; every file is left unchanged
Box.cs input
1 using System ;2 3 namespace Shapes 4 { 5 public class Box 6 { 7 private int _height; 8 private int _width; 9 10 public void SetValue <T >(string name, int value ) 11 { 12 if (name == "height" ) 13 { 14 SetHeight (value ); 15 return ; 16 } 17 if (name == "width" ) 18 { 19 SetWidth (value ); 20 return ; 21 } 22 throw new ArgumentException ("Unknown dimension " + name); 23 } 24 25 public void SetHeight (int value ) 26 { 27 _height = value ; 28 } 29 30 public void SetWidth (int value ) 31 { 32 _width = value ; 33 } 34 35 public int Area () 36 { 37 return _height * _width; 38 } 39 } 40 }
Builder.cs input
1 namespace Shapes 2 { 3 public class Builder 4 { 5 public Box Build () 6 { 7 var box = new Box (); 8 box.SetValue <string >("height" , 10 ); 9 return box; 10 } 11 } 12 }
View fixture on GitHub
# if-chainA call in another file passing "height" calls SetHeight, which the if chain runs for that value; calls passing another value or a variable are left alone
success
Target symbol M:Shapes.Box.SetValue(System.String,System.Int32)
Arguments parameter"name"value"\"height\""method"SetHeight"
Builder.cs modified
1 1 namespace Shapes 2 2 { 3 3 public class Builder 4 4 { 5 5 public Box Build (string dimension, int size) 6 6 { 7 7 var box = new Box (); 8 − box.SetValue ("height" , 10 ); 8 + box.SetHeight (10 ); 9 9 box.SetValue ("width" , size * 2 ); 10 10 box.SetValue (dimension, size); 11 11 return box; 12 12 } 13 13 } 14 14 }
Box.cs unchanged
1 1 using System ;2 2 3 3 namespace Shapes 4 4 { 5 5 public class Box 6 6 { 7 7 private int _height; 8 8 private int _width; 9 9 10 10 public void SetValue (string name, int value ) 11 11 { 12 12 if (name == "height" ) 13 13 { 14 14 SetHeight (value ); 15 15 return ; 16 16 } 17 17 if (name == "width" ) 18 18 { 19 19 SetWidth (value ); 20 20 return ; 21 21 } 22 22 throw new ArgumentException ("Unknown dimension " + name); 23 23 } 24 24 25 25 public void SetHeight (int value ) 26 26 { 27 27 _height = value ; 28 28 } 29 29 30 30 public void SetWidth (int value ) 31 31 { 32 32 _width = value ; 33 33 } 34 34 35 35 public int Area () 36 36 { 37 37 return _height * _width; 38 38 } 39 39 } 40 40 }
View fixture on GitHub
# inaccessible-method-rejectedRefuses when a redirected call could not reach the named method, which is private
refusal
Target symbol M:Shapes.Box.SetValue(System.String,System.Int32)
Arguments parameter"name"value"\"height\""method"SetHeight"
Refuses does-not-compile; every file is left unchanged
Box.cs input
1 using System ;2 3 namespace Shapes 4 { 5 public class Box 6 { 7 private int _height; 8 private int _width; 9 10 public void SetValue (string name, int value ) 11 { 12 if (name == "height" ) 13 { 14 SetHeight (value ); 15 return ; 16 } 17 if (name == "width" ) 18 { 19 SetWidth (value ); 20 return ; 21 } 22 throw new ArgumentException ("Unknown dimension " + name); 23 } 24 25 private void SetHeight (int value ) 26 { 27 _height = value ; 28 } 29 30 public void SetWidth (int value ) 31 { 32 _width = value ; 33 } 34 35 public int Area () 36 { 37 return _height * _width; 38 } 39 } 40 }
Builder.cs input
1 namespace Shapes 2 { 3 public class Builder 4 { 5 public Box Build (string dimension, int size) 6 { 7 var box = new Box (); 8 box.SetValue ("height" , 10 ); 9 box.SetValue ("width" , size * 2 ); 10 box.SetValue (dimension, size); 11 return box; 12 } 13 } 14 }
View fixture on GitHub
# not-a-constant-rejectedRefuses a value that is not a constant, which calls could not be matched against
refusal
Target symbol M:Shapes.Box.SetValue(System.String,System.Int32)
Arguments parameter"name"value"value.ToString()"method"SetHeight"
Refuses not-a-constant; every file is left unchanged
Box.cs input
1 using System ;2 3 namespace Shapes 4 { 5 public class Box 6 { 7 private int _height; 8 private int _width; 9 10 public void SetValue (string name, int value ) 11 { 12 if (name == "height" ) 13 { 14 SetHeight (value ); 15 return ; 16 } 17 if (name == "width" ) 18 { 19 SetWidth (value ); 20 return ; 21 } 22 throw new ArgumentException ("Unknown dimension " + name); 23 } 24 25 public void SetHeight (int value ) 26 { 27 _height = value ; 28 } 29 30 public void SetWidth (int value ) 31 { 32 _width = value ; 33 } 34 35 public int Area () 36 { 37 return _height * _width; 38 } 39 } 40 }
Builder.cs input
1 namespace Shapes 2 { 3 public class Builder 4 { 5 public Box Build (string dimension, int size) 6 { 7 var box = new Box (); 8 box.SetValue ("height" , 10 ); 9 box.SetValue ("width" , size * 2 ); 10 box.SetValue (dimension, size); 11 return box; 12 } 13 } 14 }
View fixture on GitHub
# nullable-parameterWith nullable reference types enabled, a nullable string parameter is matched by its constant, and a call passing null is left alone
success
Target symbol M:Shapes.Box.SetValue(System.String,System.Int32)
Arguments parameter"name"value"\"height\""method"SetHeight"
Project nullable enable
Builder.cs modified
1 1 namespace Shapes 2 2 { 3 3 public class Builder 4 4 { 5 5 public Box Build () 6 6 { 7 7 var box = new Box (); 8 − box.SetValue ("height" , 10 ); 8 + box.SetHeight (10 ); 9 9 box.SetValue (null , 2 ); 10 10 return box; 11 11 } 12 12 } 13 13 }
Box.cs unchanged
1 1 using System ;2 2 3 3 namespace Shapes 4 4 { 5 5 public class Box 6 6 { 7 7 private int _height; 8 8 private int _width; 9 9 10 10 public void SetValue (string ? name, int value ) 11 11 { 12 12 if (name == "height" ) 13 13 { 14 14 SetHeight (value ); 15 15 return ; 16 16 } 17 17 if (name == "width" ) 18 18 { 19 19 SetWidth (value ); 20 20 return ; 21 21 } 22 22 throw new ArgumentException ("Unknown dimension " + name); 23 23 } 24 24 25 25 public void SetHeight (int value ) 26 26 { 27 27 _height = value ; 28 28 } 29 29 30 30 public void SetWidth (int value ) 31 31 { 32 32 _width = value ; 33 33 } 34 34 35 35 public int Area () 36 36 { 37 37 return _height * _width; 38 38 } 39 39 } 40 40 }
View fixture on GitHub
# overloadsOnly calls of the targeted overload are redirected; a call binding to the overload taking a double keeps calling it
success
Target symbol M:Shapes.Box.SetValue(System.String,System.Int32)
Arguments parameter"name"value"\"height\""method"SetHeight"
Builder.cs modified
1 1 namespace Shapes 2 2 { 3 3 public class Builder 4 4 { 5 5 public Box Build () 6 6 { 7 7 var box = new Box (); 8 − box.SetValue ("height" , 10 ); 8 + box.SetHeight (10 ); 9 9 box.SetValue ("height" , 10.5 ); 10 10 return box; 11 11 } 12 12 } 13 13 }
Box.cs unchanged
1 1 using System ;2 2 3 3 namespace Shapes 4 4 { 5 5 public class Box 6 6 { 7 7 private int _height; 8 8 private int _width; 9 9 10 10 public void SetValue (string name, int value ) 11 11 { 12 12 if (name == "height" ) 13 13 { 14 14 SetHeight (value ); 15 15 return ; 16 16 } 17 17 if (name == "width" ) 18 18 { 19 19 SetWidth (value ); 20 20 return ; 21 21 } 22 22 throw new ArgumentException ("Unknown dimension " + name); 23 23 } 24 24 25 25 public void SetValue (string name, double value ) 26 26 { 27 27 SetValue (name, (int )Math .Round (value )); 28 28 } 29 29 30 30 public void SetHeight (int value ) 31 31 { 32 32 _height = value ; 33 33 } 34 34 35 35 public void SetWidth (int value ) 36 36 { 37 37 _width = value ; 38 38 } 39 39 40 40 public int Area () 41 41 { 42 42 return _height * _width; 43 43 } 44 44 } 45 45 }
View fixture on GitHub
# side-effects-keptThe branch of an else-if chain calls a method taking none of the parameters; a call whose other argument is a variable drops it, and a call whose other argument has side effects keeps calling the original method
success
Target symbol M:Tally.Counter.Apply(System.String,System.Int32)
Arguments parameter"mode"value"\"reset\""method"Reset"
Counter.cs modified
1 1 namespace Tally 2 2 { 3 3 public class Counter 4 4 { 5 5 private int _total; 6 6 7 7 public void Apply (string mode, int amount) 8 8 { 9 9 if (mode == "reset" ) 10 10 Reset (); 11 11 else if (mode == "add" ) 12 12 Add (amount); 13 13 } 14 14 15 15 public void Reset () 16 16 { 17 17 _total = 0 ; 18 18 } 19 19 20 20 public void Add (int amount) 21 21 { 22 22 _total += amount; 23 23 } 24 24 } 25 25 26 26 public class Client 27 27 { 28 28 private int _calls; 29 29 30 30 public void Run (Counter counter, int start) 31 31 { 32 − counter.Apply ("reset" , start); 32 + counter.Reset (); 33 33 counter.Apply ("reset" , Next ()); 34 34 counter.Apply ("add" , Next ()); 35 35 } 36 36 37 37 private int Next () => ++_calls; 38 38 } 39 39 }
View fixture on GitHub
# switch-returning-valueA switch on an enum whose case returns the named method's result; a call passing the enum member as a constant, with no receiver, calls the method directly
success
Target symbol M:Billing.Rates.Postage(Billing.Zone,System.Decimal)
Arguments parameter"zone"value"Zone.Europe"method"Europe"
Rates.cs modified
1 1 namespace Billing 2 2 { 3 3 public enum Zone 4 4 { 5 5 Domestic , 6 6 Europe , 7 7 World , 8 8 } 9 9 10 10 public class Rates 11 11 { 12 12 public decimal Postage (Zone zone, decimal weight) 13 13 { 14 14 switch (zone) 15 15 { 16 16 case Zone .Domestic : 17 17 return Domestic (weight); 18 18 case Zone .Europe : 19 19 return Europe (weight); 20 20 default : 21 21 return weight * 5m ; 22 22 } 23 23 } 24 24 25 25 public decimal Domestic (decimal weight) => weight * 1m ; 26 26 27 27 public decimal Europe (decimal weight) => weight * 2m ; 28 28 29 29 public decimal Quote (decimal weight, Zone zone) 30 30 { 31 − return Postage (Zone .Europe , weight) + Postage (zone, weight) + Postage (Zone .World , weight); 31 + return Europe (weight) + Postage (zone, weight) + Postage (Zone .World , weight); 32 32 } 33 33 } 34 34 }
View fixture on GitHub
# unknown-method-rejectedRefuses a method name the class has no method for
refusal
Target symbol M:Shapes.Box.SetValue(System.String,System.Int32)
Arguments parameter"name"value"\"height\""method"SetDepth"
Refuses unknown-method mentioning “'SetDepth'”; every file is left unchanged
Box.cs input
1 using System ;2 3 namespace Shapes 4 { 5 public class Box 6 { 7 private int _height; 8 private int _width; 9 10 public void SetValue (string name, int value ) 11 { 12 if (name == "height" ) 13 { 14 SetHeight (value ); 15 return ; 16 } 17 if (name == "width" ) 18 { 19 SetWidth (value ); 20 return ; 21 } 22 throw new ArgumentException ("Unknown dimension " + name); 23 } 24 25 public void SetHeight (int value ) 26 { 27 _height = value ; 28 } 29 30 public void SetWidth (int value ) 31 { 32 _width = value ; 33 } 34 35 public int Area () 36 { 37 return _height * _width; 38 } 39 } 40 }
Builder.cs input
1 namespace Shapes 2 { 3 public class Builder 4 { 5 public Box Build (string dimension, int size) 6 { 7 var box = new Box (); 8 box.SetValue ("height" , 10 ); 9 box.SetValue ("width" , size * 2 ); 10 box.SetValue (dimension, size); 11 return box; 12 } 13 } 14 }
View fixture on GitHub
# unknown-parameter-rejectedRefuses a parameter the method does not have
refusal
Target symbol M:Shapes.Box.SetValue(System.String,System.Int32)
Arguments parameter"dimension"value"\"height\""method"SetHeight"
Refuses unknown-parameter mentioning “'dimension'”; every file is left unchanged
Box.cs input
1 using System ;2 3 namespace Shapes 4 { 5 public class Box 6 { 7 private int _height; 8 private int _width; 9 10 public void SetValue (string name, int value ) 11 { 12 if (name == "height" ) 13 { 14 SetHeight (value ); 15 return ; 16 } 17 if (name == "width" ) 18 { 19 SetWidth (value ); 20 return ; 21 } 22 throw new ArgumentException ("Unknown dimension " + name); 23 } 24 25 public void SetHeight (int value ) 26 { 27 _height = value ; 28 } 29 30 public void SetWidth (int value ) 31 { 32 _width = value ; 33 } 34 35 public int Area () 36 { 37 return _height * _width; 38 } 39 } 40 }
Builder.cs input
1 namespace Shapes 2 { 3 public class Builder 4 { 5 public Box Build (string dimension, int size) 6 { 7 var box = new Box (); 8 box.SetValue ("height" , 10 ); 9 box.SetValue ("width" , size * 2 ); 10 box.SetValue (dimension, size); 11 return box; 12 } 13 } 14 }
View fixture on GitHub
# virtual-method-rejectedRefuses a virtual method, since an override may do something else for the value
refusal
Target symbol M:Shapes.Box.SetValue(System.String,System.Int32)
Arguments parameter"name"value"\"height\""method"SetHeight"
Refuses polymorphic-method; every file is left unchanged
Box.cs input
1 using System ;2 3 namespace Shapes 4 { 5 public class Box 6 { 7 private int _height; 8 private int _width; 9 10 public virtual void SetValue (string name, int value ) 11 { 12 if (name == "height" ) 13 { 14 SetHeight (value ); 15 return ; 16 } 17 if (name == "width" ) 18 { 19 SetWidth (value ); 20 return ; 21 } 22 throw new ArgumentException ("Unknown dimension " + name); 23 } 24 25 public void SetHeight (int value ) 26 { 27 _height = value ; 28 } 29 30 public void SetWidth (int value ) 31 { 32 _width = value ; 33 } 34 35 public int Area () 36 { 37 return _height * _width; 38 } 39 } 40 }
Builder.cs input
1 namespace Shapes 2 { 3 public class Builder 4 { 5 public Box Build (string dimension, int size) 6 { 7 var box = new Box (); 8 box.SetValue ("height" , 10 ); 9 box.SetValue ("width" , size * 2 ); 10 box.SetValue (dimension, size); 11 return box; 12 } 13 } 14 }
View fixture on GitHub