代码之家  ›  专栏  ›  技术社区  ›  StayOnTarget Charlie Flowers

是否有“get:”属性目标?

  •  2
  • StayOnTarget Charlie Flowers  · 技术社区  · 7 年前

    在微软的文档中我注意到 the following example

    [get: System.Security.SecurityCritical]
    public virtual System.Windows.Media.Imaging.BitmapSource Thumbnail { get; }
    

    注意,目标 get: “”应用于属性。

    但是在他们的 C# documentation 没有这样的目标

    assembly, module, field, event, method, param, property, return, type

    我在这两页上都没有看到任何特定版本的内容。


    此外 C# language specification 获取:


    我尝试在VS 2015的一个示例中使用它,IDE报告了错误:

    “get”不是可识别的属性位置。有效属性 此声明的位置为“属性”。此中的所有属性 块将被忽略。

    获取:


    仅供参考这很难 if not impossible 搜索字符串“get:”等。我本想找到一个答案,但这使它很难做到这一点。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Aleks Andreev Md. Suman Kabir    7 年前

    get: 目标,但只能在 get set 得到 . 请看下面的例子

    [AttributeUsage(AttributeTargets.Method)]
    public class MyAttributeAttribute : Attribute
    {
        private readonly string name;
    
        public MyAttributeAttribute(string name)
        {
            this.name = name;
        }
    }
    
    public class Test
    {
        public int Value
        {
            [MyAttribute("Get")]get;
            [MyAttribute("Set")]set;
        }
    }
    


    阿尔索 dotPeek Thumbnail 财产状

    public virtual BitmapSource Thumbnail
    {
      [SecurityCritical] get
      {
    

    看起来是这样的 获取:

    推荐文章