C#C
C#4y ago
Thinker

Interfaces containing static abstracts as type arguments

So curiously, this works
public interface IFoo
{
    static abstract IFoo Create();
}

but these don't
public interface IBar
{
    static abstract Task<IBar> CreateAsync();
}
public interface IBar<TSelf> where TSelf : IBar<TSelf>
{
    static abstract Task<IBar<TSelf>> CreateAsync();
}

The interface 'IBar' cannot be used as type argument. Static member 'IBar.CreateAsync()' does not have a most specific implementation in the interface.

Is there any way to work around this without using a regular factory interface?
Was this page helpful?