我有以下方法public abstract A : IVirtualMachineExporter
:
public override void Prepare() { ... }
我Prepare
从另一个班级打电话给B
:
public sealed class B
{
public new ExportJobRequest Request { get { return (ExportJobRequest)base.Request; } }
private void ExportTask()
{
IVirtualMachineExporter exporter = CreateExporter();
exporter.Prepare();
}
}
Request
包含public bool isAdHoc { get; set; }
。我想使用来自此属性的信息Prepare()
。我怎样才能做到这一点?我不想更改Prepare()
签名。
如何在不更改“准备签名”的情况下执行此操作?
好吧,以某种方式 Prepare
需要实例来调用isAdHoc
,因此,如果您不想更改方法签名,可以更改类或接口吗?
就像是:
IVirtualMachineExporter exporter = CreateExporter(Request);
exporter.Prepare();
或者
IVirtualMachineExporter exporter = CreateExporter();
exporter.Request = Request;
exporter.Prepare();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句