Can with
be allowed with regular classes?
#5747
Replies: 3 comments 6 replies
-
I know that the language team definitely had it on the table to enable such scenarios without explicitly using records, but I guess because the prerequisite feature got punted, this is also delayed. |
Beta Was this translation helpful? Give feedback.
-
IIRC the problem is that the method used by class A {
public string Foo { get; set; }
}
class B {
public string Bar { get; set; }
}
A x = new B() { Foo = "foo", Bar = "bar" };
var y = a with { Foo = "fizz" }; // the compiler only knows that x is an A here
Debug.Assert(y is B); // oops, y is an A, not a B |
Beta Was this translation helpful? Give feedback.
-
That would actually be nice! The key "issue" of I think C# could look for the following support:
I'm getting side-tracked but having this feature on any class and allowed inside Expression trees would be greatly beneficial to projects like linq2db. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions