Methods are only available on the interface, not the class. So you can do this instead:
IJsonAble request = new SumRequest()
var result = request.ToJson();
Or:
((IJsonAble)new SumRequest()).ToJson();
The reason for this is it allows you to add to the interface without worrying about the downstream consequences. For example, the ToJson
method may already exist in the SumRequest
class, which would you expect to be called?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…