Is there any way to easily deep copy an entire object? Maybe something with
unsafe code to make a full and completely duplicated copy of an object with
no reference ties to the original? I want everything copied, public,
private, internal, events, etc...
Thanks,
Steve 5 3121
Steve - DND wrote: Is there any way to easily deep copy an entire object? Maybe something with unsafe code to make a full and completely duplicated copy of an object with no reference ties to the original? I want everything copied, public, private, internal, events, etc...
Thanks, Steve
If the object supports ICloneable, you can use use the "Clone" method,
which is intended for exactly the purpose that your are describing.
Bennie Haelen
I think the short answer is no.
Any arbitrary object may itself have references to objects that don't
provide deep copies of themselves. A deep copy is really only good for a
specific object that provides such a copy from it's own implementation.
To attempt to deep copy using reflection to discover the object requirements
and then Activator to create instances of objects would potentially be
disastrous. What would happen for example if an object declared a
constructor with an Object parameter which internally it cast to some class
or another. You'd never be able to divine from the constructor signature how
to instantiate the object.
I think you're flogging a dead horse on this one.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Steve - DND" <steve!@!digita lnothing.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Is there any way to easily deep copy an entire object? Maybe something
with unsafe code to make a full and completely duplicated copy of an object
with no reference ties to the original? I want everything copied, public, private, internal, events, etc...
Thanks, Steve
Steve - DND wrote: Is there any way to easily deep copy an entire object? Maybe something with unsafe code to make a full and completely duplicated copy of an object with no reference ties to the original? I want everything copied, public, private, internal, events, etc...
Thanks, Steve
Reflection might be the way to go here... there are methods like
GetEvents, GetMethods, etc.
ICloneable may or may not provide a deep copy. The object is only obliged to
return what it considers to be a copy and the interface does not specify
deep copying as a requisite. Especially not for all references.
Here's another reason why the OP's post would cause problems.
Imaging providing a deep copy of a control that has a Parent object. That
parent would maintain a reference to it's child controls so no only would
such a copy create a useless and bogus parent form but that form's child
object list wouldn't even refer to the object that was copied in the first
place.
The whole concept is nasty and fraught with problems.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Bennie Haelen" <bh*****@qwest. net> wrote in message
news:ue******** ******@TK2MSFTN GP11.phx.gbl... Steve - DND wrote: Is there any way to easily deep copy an entire object? Maybe something
with unsafe code to make a full and completely duplicated copy of an object
with no reference ties to the original? I want everything copied, public, private, internal, events, etc...
Thanks, Steve
If the object supports ICloneable, you can use use the "Clone" method, which is intended for exactly the purpose that your are describing.
Bennie Haelen
Hi Steve,
"Steve - DND" wrote: Is there any way to easily deep copy an entire object? Maybe something with unsafe code to make a full and completely duplicated copy of an object with no reference ties to the original? I want everything copied, public, private, internal, events, etc...
An italian MVP answer a similar question with:
why not serializing (BinaryFormatte r) the object and than deserialize it?
Thanks, Steve
I think this could be an idea.
by
Mauro This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: dan |
last post by:
without stirring the pot too much --
could someone please point me to whatever documentation exists on the
philosophy, semantics, and practical implications of how Python
implements the assignment operator? So far I can't find much useful
in the regular documentation. I understand the basic concept that
names are bound to objects which exist on the heap, but that still
doesn't explain why a = b doesn't _always_ cause a to point to the...
|
by: jjkboswell |
last post by:
I have an XSD which I have generated a class from using the xsd.exe
tool. My XSD contains complex types within it, so that the generated
class has member variables which are of types that are also defined in
the XSD.
I deserialize XML data into instances of that class, and serialize back
to XML. So far so good.
However, in my code I have the concept of wanting to create new copies
of these deserialized objects and modifying some of...
|
by: RickH |
last post by:
Using the ms XMLDOM...
What techniques do you guys use to create deep elements in code for
appending to the main document as the user "adds" complex objects.
Currently I keep 3 files to do it like this:
1) The main xml file that the user is editing
2) The xsd file that validates the user-manipulated document
3) A "model" xml file that looks like the user xml file but only
|
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 suggested
by O'Reilly (using the "ICloneable" inhereited interface), at least
for the .NET framework.
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |