我创建了一个自定义属性类,它将检查系统安全性,并在出现安全性错误时抛出身份验证异常.
public class EntityChecker: System.Attribute
{
public EntityChecker(int entityId)
{
// doing some logic to check if the entityId is allowed to be inserted
}
}
Run Code Online (Sandbox Code Playgroud)
我想使用这个自定义属性作为实体添加函数的声明,我想将一个变量从函数传递给属性构造函数.可以这样做吗?
[EntityChecker(entityId)]
public int AddNewEntity(entityId)
{
// logic of entity addition
}
Run Code Online (Sandbox Code Playgroud)