我有一个由工具生成的部分类.
Foo.cs
public partial class Foo {
    [SomeAttribute()]
    public string Bar {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
我需要在Foo不触及Foo.cs的情况下实现以下接口:
IFoo.cs
public interface IFoo {
    string Bar {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
扩展Foo也是一种选择,但重新实现该Bar属性不是.
可以这样做吗?
是什么阻止你在另一个文件中再次这样做?
public partial class Foo : IFoo
{
}
Run Code Online (Sandbox Code Playgroud)
由于Bar属性已经存在,因此不需要重新实现它.
或者在新课堂上
public class FooExtended : Foo, IFoo
{
}
Run Code Online (Sandbox Code Playgroud)
同样,你不需要实现,Bar因为Foo已经实现了它.