C# internal interface with internal implementation

前端 未结 6 717
南笙
南笙 2020-12-15 15:03

I\'ve struck upon something I don\'t really understand.

I have a project, where I have an interface that is internal. The class that implements that interface is als

6条回答
  •  温柔的废话
    2020-12-15 15:36

    If your intention is to hide a certain implementation from outside, you can implement it explicitly like this:

    internal class LDialogService : ILDialogService, ILDialogInternalService
    {
    
        public async Task ShowAsync(ILDialogFragment fragment)
        {
            throw new NotImplementedException();
        }
    
        void ILDialogInternalService.SetComponent(LDialog component)
        {
            throw new NotImplementedException();
        }
    }
    

    In the above code, I want to expose ShowAsync method to the outside but keep SetComponent inside. Since ILDialogInternalService is internal, no one can call it from outside except through Reflection.

提交回复
热议问题