我一直在寻找解决我们公司所遇到的复杂问题的方法.该公司是4个公司联盟的一部分,这些公司在四个"地区"覆盖我们的国家.我们的分支在C#中开发了一个WebService,我们将这个项目分发给其他分支的开发人员.每个人都在自己的服务器中托管WebService.
现在,当公司不相处时,我一直在努力寻找你能期待的东西.我必须调整现有方法以适应我们的"区域需求".
所以我有这门课:
public partial class MyClass{
public static ComplexReturnType MyMethod(){
// National code. Everyone uses this block of code.
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个Regional文件夹,在将DLL分发给其他分支时,我将从编译中排除该文件夹.在这个文件夹里面我创建了文件MyClass.cs并继续这个:
public partial class MyClass{
public static ComplexReturnType MyMethod(){
// Regional code. Only my commpany will use this.
}
}
Run Code Online (Sandbox Code Playgroud)
该方法MyMethod在其他文件中调用.我理解它是如何partial工作的,但是我找不到适合我需要的解决方案而不创建子类并重写其他文件中已存在的每个调用.
有没有人知道如何处理这个问题?
回答后编辑
我决定采用策略设计模式,当我完成时,我想"如果一个分支决定覆盖任何方法,所有其他分支必须覆盖与其区域策略类中的国家代码相同的方法".
所以这不是很好.相反,我做了这个:
public class VStrategy
{
public virtual ComplexReturnType MyMethod(){
// National code. Method moved from MyClass
}
public virtual AnotherReturnType MySecondMethod(){
// National code. Method moved from MyClass
}
} …Run Code Online (Sandbox Code Playgroud) c# ×1