record
and record?
generic constraints
#7528
-
A couple of times I've written generic methods and wanted access to the As a workaround I had to reflect into usage: public static T RemoveId<T>(T obj) where T : record, IHasId
{
return obj with { Id = null };
} There's been discussion of expanding the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Without redesigning how |
Beta Was this translation helpful? Give feedback.
-
Also, see: #3859 IMO, the teams effort would be better spent describing "withers" as a pattern that can be supported by generic type constraints, rather than adding one specific generic type constraint specific to the current implementation of records. |
Beta Was this translation helpful? Give feedback.
-
I have an empty base class called DisplayRecord that all my records inherit from. I can then use constraints and get WITH. |
Beta Was this translation helpful? Give feedback.
Also, see: #3859
IMO, the teams effort would be better spent describing "withers" as a pattern that can be supported by generic type constraints, rather than adding one specific generic type constraint specific to the current implementation of records.