기본 마스터 페이지와 콘텐츠 페이지가 있고 콘텐츠 페이지에서 마스터 페이지의 일부 속성이나 메서드를 사용하려는 경우 :CodeContracts : null 참조 'this.Master'에서 메서드 호출 가능
string something = this.Master.MasterPageFile;
코드 정적 분석과 불평 계약합니다 :
warning : CodeContracts: Possibly calling a method on a null reference 'this.Master'
어떻게 내가 마스터 페이지에 액세스 할 때마다 코드 계약은 불평을 중지 할 수 있습니까?
R.
[편집]
이 한 번 봐?
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);
}
}
내가) Showfeedback을 (를 호출 할 때마다 다음해야 할 싶지 않아
:
Contract.Assume(this.Master != null)
this.Master.ShowFeedback("Test.", true);
합니까 의미가?
당신은 this.Master'가 null되지 않습니다'있도록 수 있을까? –