我創建了這個註解類
這個例子可能沒有意義,因爲它總是會拋出異常,但我仍然在使用它,因爲我只是想解釋我的問題是什麼。 由於某些原因,我的註釋永遠不會被調用任何解決方案?C# - 使用自定義註釋?
public class AuthenticationRequired : System.Attribute
{
public AuthenticationRequired()
{
// My break point never gets hit why?
throw new Exception("Throw this to see if annotation works or not");
}
}
[AuthenticationRequired]
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// My break point get here
}
在這裏你如何訪問和讀取您的自定義註解:http://msdn.microsoft.com/en-us/library /z919e8tw.aspx#Y109 –