Recently, I wanted to add an optional parameter to an extension method. The original method looked like this:
public static class Extensions { public static bool Foo(this IFoo target) { target.DoIt(true); } }
This is obviously a simplified version, but release it.
What I've done:
public static class Extensions { public static bool Foo(this IFoo target, bool flag = true) { target.DoIt(flag); } }
All I did was enter an optional parameter with a default value, right? I expected the compiler to generate an overloaded method without a flag. This has partially happened. Any code that I recompiled was able to compile and execute without any problems, even without this parameter:
... IFoo foo = new FooBar(); foo.Foo(); ...
However, any code that was created against the previous version of Foo () did not work, throwing the following exception:
Unhandled Exception: System.MissingMethodException: Method not found: 'Boolean Models.Class1.Foo()'. at DefaultParamsTests.Program.Main(String[] args)
This is obviously a problem for us, since we have a public API that our customers use, and it will be a terrific change.
The solution is to explicitly create an overload:
public static class Extensions { public static bool Foo(this IFoo target) { target.DoIt(true); } public static bool Foo(this IFoo target, bool ) { target.DoIt(true); } }
However, Resharper assumes that I can enter an optional parameter for the foo method.

If I follow refactoring, it basically does what I showed above. However, this will not work for existing code.

I looked at the generated IL using Reflector and dotPeek. Overload generation is not displayed.
What am I missing?