我向用户公开的旧版接口是这样的:
public interface IReporter
{
void Write(int site, DateTime start, DateTime end);
}
Run Code Online (Sandbox Code Playgroud)
现在我想替换函数中的参数,如下所示:
public interface IReporter
{
void Write(int site, SiteLocalDateTime start, SiteLocalDateTime end);
}
Run Code Online (Sandbox Code Playgroud)
我希望现有客户使用旧方法和新客户来使用新方法.
有关如何通过暴露单一界面实现这一点的任何想法?
选项:
保持两个接口IReporter和IReporterNew : IReporter
现在所有我的新实现都需要使用这两种方法.
不可能暴露两个界面.
如果方法的实现在您的最后,您可以将接口组合成一个.用户可以决定使用哪个.(最好将旧方法标记为过时,谢谢3dd)
public interface IReporter
{
[Obsolete]
void Write(int site, DateTime start, DateTime end);
void Write(int site, SiteLocalDateTime start, SiteLocalDateTime end);
}
Run Code Online (Sandbox Code Playgroud)
如果这不是您所追求的,您实际上应该对您的软件进行版本控制.一个适用于新客户的版本,一个针对现有客户的"遗留"版本.最终,您可以将旧客户迁移到新版本.
如果已知实际实现类型,您甚至可以在两种类型之间创建转换,但我不确定在这种情况下这是否有用.
另外,你的意思是用DateTimeOffset而不是SiteLocalDateTime?
| 归档时间: |
|
| 查看次数: |
92 次 |
| 最近记录: |