Hey guys. I have a little problem trying to clone my object, which is shown below. If you notice below, i am using a generic linked list structure to store byte arrays. The problem is when i use my Clone() method to clone this object, it doesn't clone the actual LinkedList. Any ideas on how to go about fixing this?
Much appreciated. 3 2066 Plater 7,872
Recognized Expert Expert
I think by nature of LinkedLists you have to spcifically copy it, like with: CopyTo() or something?
....
public virtual Token Clone()
{
Token _lObjReturnToke n = (Token)this.Mem berwiseClone();
Type _lObjType = _lObjReturnToke n.GetType();
FieldInfo[] _lObjFieldInfoA rray = _lObjType.GetFi elds();
foreach (FieldInfo _lObjFieldInfo in _lObjFieldInfoA rray)
{
object _lObjSourceFiel dValue = _lObjFieldInfo. GetValue(this);
if (_lObjSourceFie ldValue is Token)
{
Token _lObjSourceToke n = (Token)_lObjSou rceFieldValue;
Token _lObjClonedToke n = _lObjSourceToke n.Clone();
_lObjFieldInfo. SetValue(_lObjR eturnToken, _lObjClonedToke n);
}
}
return _lObjReturnToke n;
}
.....
[/code]
Your Token's clone method is calling clone again? Aren't you running into an infinite loop with this?
Plater 7,872
Recognized Expert Expert
Your Token's clone method is calling clone again? Aren't you running into an infinite loop with this?
You managed to quote yourself r0, lol
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Kevin |
last post by:
Hi all,
I've got a PHP4 app that I developed which I'm trying to get to run on a
PHP5 server. Everything works great, except for one thing.
There's a particular routine that creates an original object, then copies
it. (The object constructor gets some meta information from the database, so
I copy it for performance reasons). The routine...
|
by: ahaupt |
last post by:
Hi all,
I'm implementing the Clone() method through the ICloneable interface
and don't quite know how deep I need to go for a deep copy.
Example:
class A: ICloneable
{
object _val;
|
by: oDDskOOL |
last post by:
I realized today that the Hashtable.Clone only produces a shallow
copy... that makes me go mad that M$ doesn't even provide a deep copy
ctor for the Hashtable class !
mighty tech ducks might reply "oh but what if the types in hastable
don't have copy ctors defined? that could lead to dangerous
situations".
well, but was it a significant...
|
by: Neven Klofutar |
last post by:
Hi,
Can please someone send me a link or an example of deep cloning.
thanx, Neven
|
by: BenW |
last post by:
Hello,
What is the easiest way to make "deep copy" of my Hashtable?
How about with other Collection classes in C#, any documents available?
I don'r actually understand why Framework's Collection classes does not
support deep copy methods
by theself, only Clone with shallow copy.
| |
by: bonk |
last post by:
I have come across the need to distinguish between the creation of a
deep and a shallow copy and with great interest I have read this
article:
http://blogs.msdn.com/brada/archive/2004/05/03/125427.aspx
This artivle seems to hint that I should not use System.IClonable but
instead define my own interface(s) for cloning. Now since this...
|
by: Steven Blair |
last post by:
I need to perform a Deep Copy on an ArrayList.
I wrote a small sample app to prove this could be done:
ArrayList a = new ArrayList();
ArrayList b = new ArrayList();
a.Add("Hello");
b = (ArrayList) a.Clone();
|
by: raylopez99 |
last post by:
The "C# Cookbook" (O'Reilly / Jay Hilyard), section 3.26, is on deep
cloning versus shallow cloning. The scanned pages of this book are
found here: http://www.sendspace.com/file/mjyocg (Word format, 3 pp)
My question, coming from a C++ background where deep copying is done,
is why in C# you would do either deep or shallow copying as...
|
by: gits |
last post by:
This short article introduces a method that may be used to create a 'deep-copy' of an javascript object. You might ask: 'Wherefore do we need this?' ... Answer: 'Only variable-values of the basic data-types string, int, float, boolean and to make the confusion perfect :) functions too! are passed by value, all others are passed by reference.' This...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |