Implementing 2 Interfaces with 'Same Name' Properties

后端 未结 8 1937
天涯浪人
天涯浪人 2021-01-04 22:50

This seems like a reasonable (and maybe simple?) scenario, but how would you do the following:

Lets say I have 2 interfaces:

Interface ISimpleInterfa         


        
8条回答
  •  旧时难觅i
    2021-01-04 23:16

    In C# you can use explicit interface implementation:

    class Foo
    {
        string ISimpleInterface.ErrorMsg
        { get... }
    
        string IExtendedInterface.ErrorMsg
        { get... set... }
    
        string IExtendedInterface.SomeOtherProperty
        { get... set... }
    }
    

    or Interface Mapping

    class Foo
    {
        public string ErrorMsg
        { get... set... }       
    
        public string SomeOtherProperty
        { get... set... }
    }
    

    As for VB.NET, it has Implements keyword:

    Property ErrorMsg As String Implements ISimpleInterface.ErrorMsg
    
    Property OtherErrorMsg As String Implements IExtendedInterface.ErrorMsg
    

提交回复
热议问题