Skip to content

Auto-implemented property field attributes C# 7.3new scenarios

Allow attributes to be applied to the hidden backing field of auto-implemented properties.

Auto-implemented properties C# 3.0 generate a hidden backing field.

C# 7.3 allows you to annotate the hidden backing field with attributes.

Code

C#
class Location
{
    [field:JsonIgnore]
    public string Name { get; set; }
    public decimal Latitude { get; set; }
    public decimal Longitude { get; set; }
}
C#
class Location
{
    [JsonIgnore]
    private string name;
    public string Name
    {
        get { return name; }
        set { name = value; }
    }

    public decimal Latitude { get; set; }
    public decimal Longitude { get; set; }
}

More information