[Proposal] C# Next - What does Record/Data types corresponding interfaces / inheritance mean? #4006
Unanswered
BrianBu01
asked this question in
Language Ideas
Replies: 2 comments 4 replies
-
Is the only difference with normal interfaces that you can |
Beta Was this translation helpful? Give feedback.
2 replies
-
Records support inheritance: public record Individual
{
public string FirstName { get; init; }
public string LastName { get; init; }
}
public record Employee : Individual
{
public string Title { get; init; }
public int Salary { get; init; }
}
public record Contact : Individual
{
public string PhoneNumber { get; init; }
} There have been requests to have anonymous classes implement interfaces and the language design team hasn't expressed much interest in the idea. dotnet/roslyn#13 (comment) But the team has expressed interest in expanding |
Beta Was this translation helpful? Give feedback.
2 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.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm not sure what the thoughts are around defining a record/data as an interface. Lets call this construct a "register" for a lack of a better term right now. Records/Data are cool, but I feel some inheritance is warranted
Base Constructs
Data Record Type Changes
Potentially we could use with expressions to only copy the known elements.
The first method here is the way I think about it with the current constructs.
The second and third methods is how I think it should mature. Maybe Yoda speak here is more readable.
As Extension methods?
Just moving down the natural progression here. Maybe it makes sense...
Maybe it would be going backwards.
Anonymous Records/Data auto implementing
I personally would love to see Anonymous Class being converted into the construct, or auto projected...
This is a lot but the anonymous class created at compile time would just have to implement IIndividual.
The following three methods are just a natural progression in my mind of removing unnecessary items.
Just a thought. I always hated that anonymous classes were bound to the local class. I felt records with the read only POCO constructs could allow for a bit more enhancements.
Beta Was this translation helpful? Give feedback.
All reactions