S
S
stasersmailov2022-02-14 01:35:34
C++ / C#
stasersmailov, 2022-02-14 01:35:34

Is it possible to somehow more conveniently implement the default method call in interfaces?

I have an interface

public interface IEvent<Handler, Arguments> where Handler : IHandler<Handler, Arguments>
{
    public void Create(Arguments arguments)
    {
        /////
    }
}


and if you inherit from it, in order to call the Create method, you need to write such a construction
(this as IEvent<Handler, Argument>).Create(argument);

Can this be done in a more convenient way?
for example
Create<Handler, Argument>.Create(argument)
, without casts

PS Implementation through a static class and through an abstract class does not suit me in my case

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2022-02-14
@vabka

without castes

No, this syntax was invented on purpose to avoid problems from multiple inheritance.
You can't get around it - just hide it.
For example, in the case of this, you can turn something like this:
private IEvent<Handler, Argument> thisEvent => this;
// ...
thisEvent.Create(argument);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question