问题
This is a C# WPF application for a desktop. I've created a custom attribute class but in debug it never goes in there. Do I need to add something else to this class?
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class Authentication : Attribute, IPrincipal
{
public Authentication(string id)
{
throw new NotImplementedException();
}
public IIdentity Identity { get; private set; }
public bool IsInRole(string role)
{
throw new NotImplementedException();
}
}
And the method is:
[Authentication(SecurityConstants.DataEntrySupervisor)]
[Authentication(SecurityConstants.DataVerificationClerk)]
public void Submit(EventObject eventObject)
{//////////}
回答1:
An attribute is not called by the runtime in any way. It probably does not even get instanciated until you poke around with reflection.
You can look at SecurityAttribute if you want to do code security with attributes.
来源:https://stackoverflow.com/questions/22714541/debugger-is-not-entering-custom-attribute-class