Sealing an interface after implementing it

前端 未结 5 454
天命终不由人
天命终不由人 2021-01-02 16:00

I am working on a small project and I came across that problem.

The project output is a library containing an interface. I would like to implement that interface and

5条回答
  •  春和景丽
    2021-01-02 16:33

    Use an abstract base class with internal visibility. This base class is not visible outside of the library but allows you to seal the method and the class still implements the interface.

    public interface ITest
    {
        void SomeMethod();
    }
    
    internal abstract class SuperA : ITest
    {
    
        public abstract void SomeMethod();
    
    }
    
    class A : SuperA
    {
        public sealed override void SomeMethod()
        {
    
        }
    }
    

提交回复
热议问题