I have 2 classes, each returns itself in all of the function:
public class Parent{
public Parent SetId(string id){
...
return this
}
}
public class Child : Parent{
public Child SetName(string id){
...
return this
}
}
I want to enable this kind of API:
new Child().SetId("id").SetName("name");
SetName cannot be accessed since SetId returns Parent and SetName is on the Child.
How?
If you really want this fluent behavior, and the
Parentclass can be made abstract, then you could realize it like this:It is now possible to write: