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