我有以下课程,我想做一个深拷贝。
public class KeyInfo
{
public KeyInfo(IKeySetup keySetup, IKeyData data)
{
KeySetup = keySetup;
Data = data;
}
public IKeySetup KeySetup { get; set; }
public IKeyData Data { get; set; }
public KeyInfo DeepCopy()
{
var keyInfo = (KeyInfo) this.MemberwiseClone();
return keyInfo;
}
}
如何复制接口?我是否必须为接口实现 ICloneable,然后让每个具有这些接口之一的类都实现 Clone()?有没有办法避免每个类都必须实现这样的功能?