-
I would like to open a discussion about disabling
I don't think that there should be a way for interface to disable private setters in implementing type. I would disable |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
One way this is currently useful is when the interface is used as a type constraint: public class C {
public void M<T>() where T : I, new() {
var x = new T{ P = 42 };
}
}
public interface I
{
public int P { get; init; }
} |
Beta Was this translation helpful? Give feedback.
-
You can implement that interface while having class A : IA
{
private int prop;
public void SetProp(int value) => prop = value;
public int Prop { get => prop; init => prop = value; }
} Though I agree it would be nice if you didn't have to do that. |
Beta Was this translation helpful? Give feedback.
-
Imagine a code
Is it possible to enable object initializer for implementing type? |
Beta Was this translation helpful? Give feedback.
You can implement that interface while having
SetProp
, by using an explicit backing field:Though I agree it would be nice if you didn't have to do that.