什么是.NET使用IClonable接口? [英] What is the use of IClonable interface in .NET?

查看:210
本文介绍了什么是.NET使用IClonable接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道什么是利用.NET IClonable界面?

I just wanted to know what is the use of IClonable interface in .NET?

推荐答案

好了,不多真的。它获得了href=\"http://msdn.microsoft.com/en-us/library/ms229042.aspx\">框架设计指南的接口,以避免

Well, not much really. It earned a special mention in the Framework Design Guidelines as an interface to avoid.

不实现ICloneable。有
被执行
ICloneable两种通用的方式,无论是作为一个深刻的,或者
非深拷贝。深拷贝复制
克隆的对象以及由对象引用的所有对象
,递归
,直到图中的所有对象都是
复制。非深拷贝(简称
为浅如果只有顶级
引用被复制)可能会做无,或深拷贝
部分。由于
接口的合同没有指定
进行克隆的类型,不同的
类有不同的
实现。一个消费者无法
依靠ICloneable,让他们知道$ B $对象B是否是深克隆或
没有。

Do not implement ICloneable. There are two general ways to implement ICloneable, either as a deep, or non-deep copy. Deep-copy copies the cloned object and all objects referenced by the object, recursively until all objects in the graph are copied. A non-deep copy (referred to as ‘shallow’ if only the top level references are copied) may do none, or part of a deep copy. Because the interface contract does not specify the type of clone performed, different classes have different implementations. A consumer cannot rely on ICloneable to let them know whether an object is deep-cloned or not.

有一直讨论在过去约obsoleting它。我不知道什么都来了这一点,但该框架设计师都承认,它可能是一个错误。

There has been discussion in the past about obsoleting it. I am not sure what ever came of that, but the framework designers have admitted that it was probably a mistake.

如果你想支持克隆的话,我会创建和实现独立的接口 IDeepCopy IShallowCopy 等。

If you want to support cloning then I would create and implement separate interfaces IDeepCopy and IShallowCopy or the like.

这篇关于什么是.NET使用IClonable接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆