我知道我可以像这样创建自定义类属性:
[AttributeUsage(AttributeTargets.Class)]
class MyClassAttribute : Attribute {
// Logic in here to apply MyMethodAttribute to all methods
// in the class to which this is applied.
}
...然后我可以创建一个自定义方法属性,如下所示:
[AttributeUsage(AttributeTargets.Method)]
class MyMethodAttribute : Attribute { }
如何编辑这样的逻辑MyClassAttribute
,使其自动应用于MyMethodAttribute
我将其应用到的类中的所有方法?这有可能吗?
根据此文档,不可能触发其他修饰逻辑,因为无法从其Attribute
本身访问对其应用的类(或方法)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句