-
Notifications
You must be signed in to change notification settings - Fork 1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Champion "pattern-based with
expressions"
#162
Comments
Why is it tentatively planned for 7.2 if records themselves are in 8.0? |
Records build on this, not vice versa. @MadsTorgersen are you working on a proposal for this? |
I assume it's not only for records (where we need a new instance). For regular objects I think this should also work: e with { id = v }
->
(var _t = e; _t.id = v; _t) We have the same situation as |
Not sure if I'm misunderstanding your example, but if |
Yes, I think in the absence of a db.Persons.Find(id) with { Name = data.Name, ... }; or simply db.Persons.Find(id) with { data.Name, ... }; I think there is a need for null checked withers here which could be implemented via |
@alrz this will change |
@alrz, I'd see update blocks as unrelated to this. Having a with expression modify the original data would be really bad in my view. |
I think like @DavidArno We should stay with the immutable state of the About the |
I agree with @DavidArno |
Actually the pattern-based class Person {
// ...
public Person With(string name = this.Name, int age = this.Age) { ... }
} So that something like (var _t = person; _t.With(name: "newName", _t.Age)) There is a lot more moving parts here but the simple initialization does not necessarily depend on it.
This is a known papercut that could simplify various applications and there's no alternatives for that either except for member-wise assignments.
The immutable state is not a property of
I don't know what it buys you since there's no guarantee with pattern-based |
@alrz |
But this will get taken care of by the great and powerful overload resolution like any other optional arguments, won't it? |
with
expressions"with
expressions" (VS 16.8, .NET 5)
with
expressions" (VS 16.8, .NET 5)with
expressions"
I would very much like to see this added to a future language version to accomplish my example here regarding using the |
#7752 - another case when this will be very convenient. (I don't force you to do this, it's all up to you) |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
In C# 9.0, we did
with
on records only, not some generalized pattern-basedwith
expression.See also
Design meetings
https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-09-26.md#construction-improvements
The text was updated successfully, but these errors were encountered: