-
right now im having a bunch of interfaces describing my model. I would like to convert the implementations into records. so the interface gets init properties instead of readonly properties. but how do I express that the object is withable in the interface? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can't right now. For the next version of C#, the language team intends to add public interface IMyModel
{
[Factory]
IMyModel With();
} |
Beta Was this translation helpful? Give feedback.
You can't right now.
For the next version of C#, the language team intends to add
[Factory]
: an attribute that indicates a method return is always a fresh instance, so it's okay to put an object initializer after such a call. If you then define a method namedWith
that takes no parameters and returns the same object type, the compiler will use that pattern to allowwith
as a keyword on instances of that object.See here.