Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a "get:" attribute target?

Tags:

c#

attributes

In Microsoft's docs I noticed the following example:

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

Notice that the target "get:" is applied to the attribute.

However in their C# documentation there is no such target. They list only:

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

I don't see anything version-specific on either of these pages.


Furthermore, the C# language specification doesn't include get: either (page 395).


I tried using it anyway in a sample in VS 2015, and the IDE reported the error:

'get' is not a recognized attribute location. Valid attribute locations for this declaration are 'property'. All attributes in this block will be ignored.

Is get: valid in some circumstances? Is it a mistake in their documentation?


FYI it is very hard if not impossible to search for the string "get:" on SO. I expected to find an answer to this already but that made it pretty hard to do so.

like image 653
StayOnTarget Avatar asked Mar 26 '19 14:03

StayOnTarget


1 Answers

I can't find anything about get: target, but it is possible to apply atrribute only on get part of property or different attributes on set and get. Please see example below

[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;
    }
}

EDIT:
Also dotPeek decompiler shows me Thumbnail property like

public virtual BitmapSource Thumbnail
{
  [SecurityCritical] get
  {

so it looks like that get: target does not exists

like image 112
Aleks Andreev Avatar answered Sep 21 '22 17:09

Aleks Andreev