【问题标题】:Limit where C# custom attribute can be used限制可以使用 C# 自定义属性的位置
【发布时间】:2016-09-23 13:55:11
【问题描述】:

我正在创建一个我只想在接口上指定的属性。有没有办法在 C# 中做到这一点?

【问题讨论】:

  • 用 [AttributeUsage(AttributeTargets.Interface)] 装饰你的属性
  • 就是这个,谢谢!

标签: c# attributes custom-attributes


【解决方案1】:
 [AttributeUsage(AttributeTargets.Interface)]
 public class MyAttribute : Attribute
 {
 }

You have more options

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-02
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    相关资源
    最近更新 更多