Hi there
this is my scenario
public interface ISomething
{
void DoStuff();
//...
}
public class Something : ISomething
{
private readonly ISomethingElse _somethingElse;
//...
public Something (ISomethingElse somethingElse)
{
Contract.Requires(somethingElse != null);
_somethingElse = somethingElse;
}
public void DoStuff()
{
// *1* Please look at explanaition / question below
_somethingElse.DoThings();
}
}
So, if in 1 and with the static checker on, I ll get a warning saying that _somethignElse is possibly null, if I add a contract it will give me the error
[Type]implements interface method {Interface.Method} thus cannot add requires
So whats the best thign to do here options I see
1) a guard clause , tho it seems a bit extreme 2) a Contract.Assume 3) hidden third option that I havent thought of
Please note the field is readonly so ,actually after i set teh value in ctor is not possible to change so I see the warning from code contracts a bit irrelevant