Is there a particular reason why a generic ICloneable does not exist?
It would be much more comfortable, if I would not need to cast it everytime I clone something.
Can you explain to me why I should inherit from ICloneable and implement the Clone() method?
If I want to do a deep copy, can't I just implement my method? Let's say MyClone()?
Why should I inherit from ICloneable? What are the advantages? Is it…
What is the proper way of implementing ICloneable in a class hierarchy? Say I have an abstract class DrawingObject. Another abstract class RectangularObject inherits from DrawingObject. Then there are multiple concrete classes like Shape, Text,…
Surprisingly, String.Clone() doesn't return a copy of a string as String.Copy() would do. Instead, it returns 'this', the original string.
I would like to understand why the .Net Framework team choose to go this way.
As per MSDN:
The ICloneable…
I am porting an existing .NET class library to a Portable Class Library. The .NET library makes extensive use of the ICloneable interface, which is not included in the portable subset.
Typically, I am faced with class definitions like this in the…
Check this code:
.. class someclass : IDisposable{
private Bitmap imageObject;
public void ImageCrop(int X, int Y, int W, int H)
{
imageObject = imageObject.Clone(new Rectangle(X, Y, W, H), imageObject.PixelFormat);
}
…
I've done some reading and cant seem to wrap my head around what the best approach would be to clone a List(of class) in my VB2010 project. I have three classes that are related like so
Public Class City
'here are many fields of type string and…
I have the following:
public class InstanceList : List {}
I would like to make this cloneable. Following the example here: Why no ICloneable?
I tried the following:
public interface ICloneable : ICloneable Where T :…
I am attempting to create a base class and a derived class that both implement ICloneable. It seems to me that the base class Clone method should take care of all the base class properties and the derived class Clone method all of the derived class…
I want to clone an object with using the ICloneable interface
and for some reason I can't clone in my program. Here is my code:
public class GeoInfo : ICloneable
{
private long InfoID;
private string InfoName;
private Location…
Resharper complains about the following code, saying that the last null check is redundant as the 'expression is always false':
ICloneable data = item as ICloneable;
if (data == null)
throw new InvalidCastException("blah blah, some error…
Assume I have a class A, and B which derives from A:
class A : ICloneable
{
public object Clone() {...}
}
class B : A, ICloneable
{
public object Clone() {...}
}
which gives
'B.Clone()' hides inherited member 'A.Clone()'. Use the new…
I've got a Lambda Expression which is a function that does some operation in a previous context. Consequently, I will need to clone this object and carry over the expression to the new context, but I am concerned that there would be local values…