使用属性在事件上使用目标
在事件(字段定义的事件)上使用属性时,存在三种可能的属性目标,即事件、字段和方法。我了解事件和字段目标的用法,但是方法目标适用于哪里。
例如
[AttributeUsage(AttributeTargets.All,AllowMultiple=false,Inherited=true)]
internal class TestAttribute : Attribute
{
}
internal class Test
{
[event: Test]
[field: Test]
[method: Test]
public event Action action;
}
There are three possible attribute targets when using attributes on events (field defined events) and those are event, field and method. I understand the usage of event and field target, but where does the method target apply.
for example
[AttributeUsage(AttributeTargets.All,AllowMultiple=false,Inherited=true)]
internal class TestAttribute : Attribute
{
}
internal class Test
{
[event: Test]
[field: Test]
[method: Test]
public event Action action;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,它应用于编译器生成的“添加”和“删除”方法(执行订阅/取消订阅的方法):
As far as I can tell, it's applied to the "add" and "remove" methods generated by the compiler (the methods which perform the subscription/unsubscription):