-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
PrintMembersIgnoreAttribute for records
- Proposed
- Prototype: Not Started
- Implementation: Not Started
- Specification: Not Started
Summary
Currently, there is no way for the developer to exclude specific fields or properties from record's PrintMembers.
Motivation
-
If a record contains an instance member of its same type, PrintMembers will get called recursively forever. Converting the instance member to be a static is one way to fix this, but being able to completely exclude an instance member seems to be a great addition.
-
If one of the properties doesn't have an overridden
ToString()
implementation. It's useless to be printed, the developer might want to exclude it, but in that case marking it as static wouldn't be always an available option.
Detailed design
A new attribute is introduced:
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class PrintMembersIgnoreAttribute : Attribute { }
If GenerateMethodBody in SynthesizedRecordPrintMembers found the field/property being decorated with this attribute, it shouldn't include it.
Drawbacks
Alternatives
Unresolved questions
- If this attribute is applied to non-record members, should the compiler warn and ignore it, or error it completely?
- Should the developer be able to force including statics and constants with a similar attribute (e.g.
ForceIncludeInPrintMembersAttribute
)?