If I have a basic master page and content page and I want to use some property or method of the master page from the content page, such as:
string something = this.Master.MasterPageFile;
Code Contracts static analysis will complain with:
warning : CodeContracts: Possibly calling a method on a null reference 'this.Master'
How can I get Code Contracts to stop complaining whenever I want to access the master page?
R.
[Edit]
Take a look at this?
public partial class Manage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Master.ShowFeedback("Test.", true);
}
[ContractInvariantMethod]
private void ObjectInvariants()
{
Contract.Invariant(this.Master != null);
}
}
I don't want to have to do the following every time I want to call Showfeedback():
Contract.Assume(this.Master != null)
this.Master.ShowFeedback("Test.", true);
Does that make sense?