How to call explicit interface implementation methods internally without explicit casting?

后端 未结 7 763
谎友^
谎友^ 2020-12-08 18:44

If I have

public class AImplementation:IAInterface
{
   void IAInterface.AInterfaceMethod()
   {
   }

   void AnotherMethod()
   {
      ((IAInterface)this)         


        
7条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 19:17

    You can't, but if you have to do it a lot you could define a convenience helper:

    private IAInterface that { get { return (IAInterface)this; } }

    Whenever you want to call an interface method that was implemented explicitly you can use that.method() instead of ((IAInterface)this).method().

提交回复
热议问题