Default implementation in interface is not seen by the compiler?
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?
Try using (new SumRequest() as IJsonAble).ToJson();
to help the compiler a bit.
Anyway, I'm sure what you're after is (this as IJsonAble).ToJson()
, assuming you want to apply ToJson on current SumRequest instance.