-
Assume I have a struct public struct Point
{
public double X {get; init;}
public double Y {get; init;}
} I assume the init-only does not work for factory methods: public static Point Create() => new Point(); so I cannot write Create().X = 10; correct? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I don't think it's going to be in 9.0, but the idea that the LDT wants to do is allowing to annotate the factory method with an attribute (eg. |
Beta Was this translation helpful? Give feedback.
-
https://github.com/dotnet/csharplang/blob/master/meetings/2020/LDM-2020-04-20.md
|
Beta Was this translation helpful? Give feedback.
-
Thanks to both of you. |
Beta Was this translation helpful? Give feedback.
I don't think it's going to be in 9.0, but the idea that the LDT wants to do is allowing to annotate the factory method with an attribute (eg.
[Factory]
) which the compiler recognizes and will limit what you can actually return (onlynew
and the return value of other[Factory]
methods), and that will let you add an object initializer at the callsite. More information here (the example is onWith()
, but that's just a special case of the more general feature).