Why do I need "field:" in my attribute declaration "[field:NonSerialized]"?
.net, c#, nonserializedattribute, serialization
Solution
The C# compiler usually has no trouble figuring out what part of a declaration the attribute applies to. I can think of three cases where you might use it:
- Attributes that apply to the assembly. Very visible in AssemblyInfo.cs
- An attribute applied to the return value of a P/Invoke declaration, [return:MarshalAs]
- Having the attribute apply to the backing variable of a property or event without accessors. Your case.
Problem
I can't find "field" listed as a C# keyword anywhere. Does anyone know the background on this?