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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With