How can I implement static methods on an interface?

前端 未结 8 1961
生来不讨喜
生来不讨喜 2020-12-07 21:26

I have a 3rd party C++ DLL that I call from C#.

The methods are static.

I want to abstract it out to do some unit testing so I created an interface with the

8条回答
  •  渐次进展
    2020-12-07 22:17

    C# 8 Allows Static Members on Interfaces

    Beginning with C# 8.0, an interface may define a default implementation for members. It may also define static members in order to provide a single implementation for common functionality.

    interface (C# Reference)

    E.g.

    public interface IGetSomething
    {
        public static string Something = "something";
    }
    
    var something = IGetSomething.Something;
    

提交回复
热议问题