I realize you can't get the target entity in the Attribute itself, but what about in an associated Permission object when using a CodeAccessSecurityAttribute? The Permission object gets called at runtime so it seems there should be a way but I'm at a loss.
public sealed class MySecurityAttribute : CodeAccessSecurityAttribute
{
public override IPermission CreatePermission()
{
MySecurityPermission permission = new MySecurityPermission();
//set its properties
permission.Name = this.Name;
permission.Unrestricted = this.Unrestricted;
return permission;
}
}
public class MySecurityPermission : IPermission, IUnrestrictedPermission
{
public MySecurityPermission(PermissionState state)
{
// what method was the attribute decorating that
// created this MySecurityPermission?
}
public void Demand()
{
// Or here?
}
}