record-classes

How do I target attributes for a record class?

隐身守侯 提交于 2020-12-27 06:31:51
问题 When defining a record class, how do I target the attributes to the parameter, field or property? For instance, I would like to use JsonIgnore but this doesn't compile as it has an attribute usage restriction to the field or property: record Person(string FirstName, string LastName, [JsonIgnore] int Age); 回答1: To target the various parts of the expanded class, use the appropriate attribute target. For instance: // Target the property, use `property` record Person(string FirstName, string

How do I target attributes for a record class?

孤人 提交于 2020-12-27 06:30:39
问题 When defining a record class, how do I target the attributes to the parameter, field or property? For instance, I would like to use JsonIgnore but this doesn't compile as it has an attribute usage restriction to the field or property: record Person(string FirstName, string LastName, [JsonIgnore] int Age); 回答1: To target the various parts of the expanded class, use the appropriate attribute target. For instance: // Target the property, use `property` record Person(string FirstName, string

How do I target attributes for a record class?

对着背影说爱祢 提交于 2020-12-27 06:29:26
问题 When defining a record class, how do I target the attributes to the parameter, field or property? For instance, I would like to use JsonIgnore but this doesn't compile as it has an attribute usage restriction to the field or property: record Person(string FirstName, string LastName, [JsonIgnore] int Age); 回答1: To target the various parts of the expanded class, use the appropriate attribute target. For instance: // Target the property, use `property` record Person(string FirstName, string