0
我要檢查一些條件在我的代碼,如果條件不滿足我要顯示在調試錯誤時,VS(C#)錯誤顯示,
我試圖做到這一點與Debug.Assert()
,但它並沒有像工作我所期望的。 這是我的代碼:如何向調試器發送錯誤消息並停止調試?
public class Inflicted : Attribute
{
public string[] Names{ get; set; }
public Inflicted (params string[] Names) {
// check if the params empty;
// so show the error in debuger.
Debug.Assert(Names.Length == 0, "The Inflicted cant be with zero argument");
this.Names= Names;
}
}
當我使用這個屬性不帶任何參數我的項目構建成功
// ...
[Inflicted]
public string Title
{
get { return _Title; }
set { _Title = value;}
}
// ...
但我想這個屬性的用戶不能使用我的屬性只與爭論。 看起來像:[Inflicted("param1", "param2")]
您是否期望在調試期間或編譯期間發生錯誤? –
@WillemDuncan是的,我想導致編譯錯誤。 –