您可以在部分 class 中扩展非部分方法吗?

Can you extend a non partial method in a partial class?

我有一个生成的部分 class

public partial interface IPartialInterface
{
   Task<object> Method(string param)
}
public partial class PartialClass : IPartialInterface
{
    public Task<object> Method(string param)
    {
        // does stuff
    }
}

我想扩展方法,这样我就可以插入一些逻辑,然后根据我的逻辑让PartialClass.Method逻辑接管或停止它。

对于有同样问题的人,这对我有用:

    public partial interface IGeneratedPartialInterface
    {
        Task<object> Method(string param)
    }
    public partial class GeneratedPartialClass : IGeneratedPartialInterface
    {
        public Task<object> Method(string param)
        {
             // does stuff
        }
    }
        
    public interface MyInterface
    {
        Task<object> MethodExtended(string param)
    }
        
    // added by me, but must be named as the generated partial class
    public partial class GeneratedPartialClass : MyInterface
    {        
        public Task<object> MethodExtended(string param)
        {
            // my logic here example
            if (isInCache(param))
            {
                // do stuff
            }
            else 
            {
                return this.Method(param)
            }
        }
    }