This is my first proposal so please go easy on me. :-)
It would be cool if we could use this as the return type for instance methods, to indicate that the method returns its containing object.
Use cases include builder objects and other fluent APIs.
public class PizzaBuilder {
private string _dough;
private string _sauce;
private string _topping;
public this UseDough(string dough) => _dough = dough;
public this UseSauce(string sauce) => _sauce = sauce;
public this UseTopping(string topping) => _topping = topping;
public Pizza Build() {
return new Pizza(_dough, _sauce, _topping);
}
}
It would be synonymous for the following:
public class PizzaBuilder {
private string _dough;
private string _sauce;
private string _topping;
public PizzaBuilder UseDough(string dough) {
_dough = dough;
return this;
}
public PizzaBuilder UseSauce(string sauce) {
_sauce = sauce;
return this;
}
public PizzaBuilder UseTopping(string topping) {
_topping = topping;
return this;
}
public Pizza Build() {
return new Pizza(_dough, _sauce, _topping);
}
}
This is my first proposal so please go easy on me. :-)
It would be cool if we could use
this
as the return type for instance methods, to indicate that the method returns its containing object.Use cases include builder objects and other fluent APIs.
It would be synonymous for the following: