Questions tagged [icloneable]

Questions regarding .NET ICloneable Interface

.NET ICloneable Interface

Supports cloning, which creates a new instance of a class with the same value as an existing instance.

Docs: https://msdn.microsoft.com/en-us/library/system.icloneable%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

Famous question: Proper way to implement ICloneable

47 questions
3
votes
5 answers

Change property of immutable type

I have stored immutable types in a temporary CQRS read store (query/read side, in fact implemented by a simple List with abstraction access layer, I don't want to use a full blown document database at this point). These read stores contains items…
Beachwalker
  • 7,685
  • 6
  • 52
  • 94
3
votes
1 answer

How to correct implement ICloneable in a tree hierarchy rooted by an abstract class?

Given a tree hierarchy, suppose it is the following: abstract class Person : ICloneable ... sealed class Student : Person ... I want to implement the ICloneable interface. In the Student.Clone method I wish to do something like: { Student…
mdarefull
  • 829
  • 2
  • 14
  • 24
3
votes
2 answers

Does memberwiseclone copy DateTime, or must it be explicitly set?

I'm implementing ICloneable on a ton of custom objects. Some of the objects have a type of DateTime, which is a struct value. I know this value can be copied using newDateTime = oldDateTime, but if I use MemberwiseClone() on my object, does it…
KrisSodroski
  • 2,796
  • 3
  • 24
  • 39
2
votes
3 answers

Creating objects driven by the database to populate a Treeview - very slow

I have an application that reads a table from a database. I issue an SQL query to get a result set, based on a unique string value I glean from the results, I use a case/switch statement to generate certain objects (they inherit TreeNode BTW). …
Vidar
  • 6,548
  • 22
  • 66
  • 96
2
votes
3 answers

ICloneable Vs Strongly Typed Function Vs Being Lazy

Hi Folks I need to deep clone some custom objects that references other custom objects and these may reference other cust... and so on you get the idea. I'm just at the documentation & conception stage at the moment so wan't to get it right. Q1. Why…
baileyswalk
  • 1,198
  • 2
  • 17
  • 29
2
votes
1 answer

Object deep copy in Silverlight

I was trying to create copy of objects in silverligth 5 where interfaces like IFormatters and IcCloanble do not support. * My objects are like this: (Note that these obkjects are obtained on deserializing xml): I tried to do copy like this: …
user3735822
  • 337
  • 2
  • 12
1
vote
1 answer

How do I know if my copy is going to be deep or shallow, when using ICloneable?

As stated on the Microsoft's site, ICloneable interface can either deep or shallow copy: An implementation of Clone can perform either a deep copy or a shallow copy. In a deep copy, all objects are duplicated; in a shallow copy, only the top-level…
aca
  • 1,071
  • 5
  • 15
1
vote
1 answer

How Cloneable to all field

Possible Duplicate: Deep copy of List public class MyClass : ICloneable { private List m_list = new List(); public MyClass() { List.Add("1111"); List.Add("2222"); List.Add("3333"); …
Mediator
  • 14,951
  • 35
  • 113
  • 191
1
vote
3 answers

Test if generic type supports ICloneable

I have a structed called ValueFrequency which starts its life as a struct where you (for statistical reasons) could store a (double) value, and an (int) frequency (telling how many times this value occured in a set of data. E.g. if you had a…
1
vote
2 answers

Proper way to Clone a List> in C#

I'm struggling to clone a list of lists of a reference type. I tried to implement ICloneable in my reference class, however, it don't seems to call the Clone() method in it. Code: public class Solid : ICloneable{ private double[,] _points; …
FrankTominc
  • 119
  • 1
  • 10
1
vote
1 answer

ICloneable deepcopy of an object in .net

I'm trying to add a deep-copy method using ICloneable to classes that have been auto-generated from an xsd using xsd.exe. I can get it to work on a simple level but as soon as the objects become nested then the clone method doesn't work. I'm pretty…
user1607914
  • 105
  • 1
  • 3
  • 12
1
vote
1 answer

Nightmare with passing inheritance through WCF

We have a class in WCF Service like the following [DataContract] public class SampleClass:ICloneable { public object Clone() { return MemberwiseClone(); } .... } On client side where Service References added, I open the Reference in Object…
user3375740
  • 245
  • 1
  • 3
  • 11
1
vote
1 answer

VB.Net clone hierarchy where parent has reference to child and vice versa -> circular reference

This is the situation: Class A Implements ICloneable Public Property Children As List(Of Child) Public Function Clone() As Object Implements ICloneable.Clone Return New A With { .Children =…
Recipe
  • 1,398
  • 3
  • 16
  • 29
1
vote
2 answers

ICloneable Interface

This relates to the "Watson et al: Beginning Visual C# Chapter 10: exercise 4": Implement the ICloneable interface on the People class to provide deep copying capability class People : DictionaryBase: ICloneable public void DictAdd(Person…
Laurie Stearn
  • 959
  • 1
  • 13
  • 34
1
vote
2 answers

A doubt with the ICloneable interface in petshop 4.0?

In the 'DBUtility' project of Petshop 4.0,the abstract class SqlHelper has a method 'GetCachedParameters': public static SqlParameter[] GetCachedParameters(string cacheKey) { SqlParameter[] cachedParms =…
Jring Qin
  • 347
  • 1
  • 4
  • 11