Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2006

Tip: Looking for answers? Try searching our database.

Creating copy of structure instance via reflection?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Larry Minton - 22 May 2006 20:46 GMT
I'm checking to see if there is an easy way to "clone" a structure
instance via reflection. I have a System::Object that boxes a
structure instance, and I want to create a new structure instance with
the same field values.

I can say something like:

Object ^ l_pObject = GetObject();
ICloneable ^ l_pICloneable = dynamic_cast<ICloneable^>(l_pObject);
if (l_pICloneable)
 return intern(l_pICloneable->Clone());
// see if a structure.
Type ^ l_pType = GetType();
if (l_pType->IsValueType && !l_pType->IsPrimitive)
{
 Object ^ l_pNewObject = Activator::CreateInstance(l_pType);
.. add code here to get/set individual fields ...
 return intern(l_pNewObject);
}
// can't clone
return this;

I can do the ".. add code here to get/set individual fields ...", but
it seems like there probably is an easier way.

Thanks, Larry
www.fruitfruit.com - 24 May 2006 09:05 GMT
I guess the following post is relevant to your question, although not
exactly the same.
http://www.codeguru.com/columns/vb/article.php/c11859/
Use Interop Code and Overlap Fields with the Union Construct in VB .NET

> I'm checking to see if there is an easy way to "clone" a structure
> instance via reflection. I have a System::Object that boxes a
[quoted text clipped - 22 lines]
>
> Thanks, Larry

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.