Given the following two interfaces (these are small examples, not my actual implementation):
public interface IAssertion<T> {
IAssertion<T> IsNotNull();
IAssertion<T> Evaluate(Predicate<T> predicate)
}
public interface IStringAssertion : IAssertion<string> {
IStringAssertion IsNotNullOrEmpty();
}
and a static factory that will return the appropriate interface, for example:
public static class Require {
public static IAssertion<T> That<T>(T value) {
...
}
public static IStringAssertion That(string value) {
...
}
}
I should be able to do the following:
public void TestMethod(SomeClass a, string b) {
Require.That(a).IsNotNull();
Require.That(b).IsNotNullOrEmpty().Evaluate(SomeMethodThatAcceptsString);
}
This code compiles and will actually run. I can even set up tests that pass, such as:
Assert.IsInstanceOf<IStringAssertion>(Require.That(string.Empty));
Assert.IsNotInstanceOf<IStringAssertion>(Require.That(new object());
The problem I am running into and the whole point of this question, is that Visual Studio 2005 intellisense is not resolving the differences between the two.
When I type Require.That("...").
I should expect to see a list of
Evaluate(Predicate predicate) IsNull() IsNotNullOrEmpty()
but instead I see nothing.
I would really like to keep the same method name for the overloads. I want to keep the generic overload because of the predicate in the Evaluate method of the IAssertion interface.
Also, I know I can do something close to this using extension methods, but that is not an option because I still want to support .Net 2.0 and would like to keep the fluent api.
Updated:
There have been some good answers that involve third party add-ons to Visual Studio. Unfortunately I am not in a position to either install or purchase add-on tools for Visual Studio due to the corporate red tape that I am developing under. (I hate politics!)
I am looking for a code only option that will work in both Visual Studio 2005 and Visual Studio 2008.
Updated:
This works in Visual Studio 2008. Thank you, Luke. That only leaves Visual Studio 2005.