record generic constraint #4315
Unanswered
ekgurney14
asked this question in
Language Ideas
Replies: 3 comments 2 replies
-
Records are designed to not be distinguishable with normal classes. This code isn't achievable now, because the I'd prefer to achieve things like this with HKT. |
Beta Was this translation helpful? Give feedback.
2 replies
-
See #3859, #39 (comment) and #3899 for earlier discussions of this |
Beta Was this translation helpful? Give feedback.
0 replies
-
The key takeaway from those previous discussions is that hopefully the 'with' expression will be usable with classes in c# 10. They eliminating my need from the initial question. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Would it be possible in the future to allow record to be a constraint on a generic class/record.
I would like to be able to create a class where I am able to use 'with' record creation on the generic type to promote immutability.
e.g.
``
public interface IValue
{
public int Value {get;init;}
}
public class Api where T : record, IValue
{
public T DoSomething(T item) => item with { Value = 1 };
}
``
Beta Was this translation helpful? Give feedback.
All reactions