Imagine the following class diagram and what the compiler would do with the code below.
public class ObjectHelper { public static void Do(BaseObject inp, bool doit=true) { Trace.TraceInformation("do something base object"); } public static void Do(IOther inp, bool doit=true, bool may=true){ Trace.TraceInformation("do something other"); } public static void ThisIsDifferent() { var o = new MyObject(); ObjectHelper.Do(o, doit: false); } }
VS2013
Compiling the source in VS2013 will succeed. Running the ObjectHelper.ThisIsDifferent() in the Immediate Window will print do something base object. So we can conclude the compiler prefers the best matching method signature. All parameters are set for the method that is executed.
VS2013 Roslyn Preview
Installing the Roslyn Preview extension in VS2013 will result in a compiler error:
The call is ambiguous between the following methods or properties: ‘ObjectHelper.DoSomething(BaseObject, bool)’ and ‘ObjectHelper.DoSomething(IOther, bool, bool)’
I’ve noticed that lots of spaces at the end of source files can throw exceptions too. Browsing to the Roslyn Github project, you’ll see that Roslyn is no longer available for Visual Studio 2013. This means no more support / updates or fixes.
VS2015 CTP6
On Azure you can get a VM with VS2015 CTP6 pre-installed. When I build my sample there no build errors and the immediate window returns the same trace statement as VS2013. Seems like the bug is fixed in Roslyn.
References
Disabling Roslyn Preview, solving a hickup in disabling the preview
Roslyn Github project