Tag: icloneable

在派生类中可克隆

假设我有一个A类和B类,它来自A : class A : ICloneable { public object Clone() {…} } class B : A, ICloneable { public object Clone() {…} } 这使 ‘B.Clone()’ hides inherited member ‘A.Clone()’. Use the new keyword if hiding was intended. 警告。 (1)建议的方式是什么? 使用new或声明A.Clone()作为virtual和override B ? (2)如果A有一些成员并在A.Clone()正确克隆,是否有一种简单的方法可以在B.Clone()克隆它们,还是必须在B.Clone()明确克隆它们?

Silverlight中的对象深层复制

我试图在silverligth 5中创建对象的副本,其中IFormatters和IcCloanble等接口不支持。 * 我的对象是这样的:(注意这些obkjects是在反序列化xml时获得的):我试着像这样复制: [XmlRoot(ElementName = “component”)] public class Component { [XmlElement(“attributes”)] public Attributes Attributes { get; set; } [XmlIgnore] public Attributes atrbtOrginal = new Attributes(); [XmlIgnore] public Attributes atrbtCopy{ get; set; } } public Component() { atrbtCopy= atrbtOrginal ; } 当然它不会工作,然后我在Google上搜索这个代码: public static class ObjectCopier { public static T Clone(T source) { if (!typeof(T).IsSerializable) […]