all groups > dotnet academic > july 2004 >
You're in the

dotnet academic

group:

C# question that should be simple...


C# question that should be simple... Alasdair Turnbull
7/18/2004 9:00:02 PM
dotnet academic:
Friends,

How can I make a shallw copy of any object in C# .NET? For example, I want to make a copy of a managed DX9 Directplay NetworkPacket. The class is sealed so I can't derive from it and use MemberwiseClone. I'm sure there is a simple (and probably obvious) way to do this but it eludes me.

Re: C# question that should be simple... Marco Barzaghi
8/6/2004 12:58:47 AM
I think that if the class is sealed the designer has his good reason...

If you want you can use reflection. U get all values of all fields (public and not public) of the
class... then you create a new instance of the class and with reflection initialize all fields with
the data that you have read from the original.

....I don't think it's a good idea to do a shallow copy of a "DX9 Directplay NetworkPacket"... I
think there is too many handle to clone.... Are U sure there isn't a copy constructor for the class?

HTH M.rkino

--
Marco Barzaghi - [MVP - MCP]
http://mvp.support.microsoft.com - http://italy.mvps.org
UGIDotNet - User Group Italiano .NET, http://www.ugidotnet.org
Read my WebLog: http://www.ugidotnet.org/436.blog

AddThis Social Bookmark Button