csharp-analyzer
csharp-analyzer copied to clipboard
Add feature for method overloading exercise
See the method-overloading exercise.
The following feature should be added:
There are three overloaded Describe()
methods which each take a single parameter (character, destination and travel method. They are not addressed by this issue.
In addition to the above 3 overloads the instructions require that the code should allow:
-
the caller to specify all 3 aspects in one call (character + destination + travel method).
-
or the caller to specify just 2 aspects, character and destination, in which case
TravelMethod.Walking
should be used as the travel method.
There are 2 ways for the student to approach this. Firstly, to include one overload with 3 parameters and a separate one with 2 parameters. In fact the boilerplate takes this approach.
public static string Describe(Character character, Destination destination, TravelMethod travelMethod) {}
public static string Describe(Character character, Destination destination) {}
The alternative is to omit the 2 parameter method altogether and give the final (TravelMethod
) parameter of the 3 parameter method a default value of TravelMethod.Walking
as is shown in the example code.
public static string Describe(Character character, Destination destination, TravelMethod travelMethod = TravelMethod.Walking) {}
The analyzer should report that the second approach, giving the parameter a default value, is preferable. This should also handle the case where named parameters are used.