Chaos Project

Game Development => General Discussion => Topic started by: G_G on April 09, 2011, 06:16:53 pm

Title: [C#] Copying and Pasting Objects/Classes?
Post by: G_G on April 09, 2011, 06:16:53 pm
Alright so here's this class.
class Object
{
    // variables here
}


I want to be able to copy an instance of this class to the clipboard and then be able to access it. I'm pretty sure this is possible but I'm unsure on how to go about it. And of course how would I access the data? How would I check if this object is in the clipboard or not? Thanks for the help guys.
Title: Re: [C#] Copying and Pasting Objects/Classes?
Post by: Ryex on April 09, 2011, 08:13:29 pm
the clip board only really holds raw data it ins't capable of holding an object. your two options are serializing the object and passing the byte sting to the clipboard and reconstruct it on the other side. or, if your copy pasting within the same program instance as I amuse you are, you can pass to the clip board some identifying information that can point the other side to the where the object you need to access is in the program. and then use that information to access it.
Title: Re: [C#] Copying and Pasting Objects/Classes?
Post by: winkio on April 09, 2011, 08:19:21 pm
you can extend the clipboard to hold different types of objects.
Title: Re: [C#] Copying and Pasting Objects/Classes?
Post by: Ryex on April 09, 2011, 09:12:23 pm
really?

hmm perhaps this will help G_G it seems my knolege of what the clipboard can do is wrong.
http://weblogs.asp.net/andrewrea/archive/2008/02/18/add-object-to-clipboard-using-c-in-a-couple-of-ways.aspx (http://weblogs.asp.net/andrewrea/archive/2008/02/18/add-object-to-clipboard-using-c-in-a-couple-of-ways.aspx)
Title: Re: [C#] Copying and Pasting Objects/Classes?
Post by: G_G on April 09, 2011, 11:35:00 pm
Yup. I got it thanks guys. I also found this. Just the simplest way to do it I think.

http://blog.csharphelper.com/2010/05/13/copy-and-paste-objects-to-the-clipboard-in-c.aspx
Title: Re: [C#] Copying and Pasting Objects/Classes?
Post by: Blizzard on April 10, 2011, 04:24:37 am
I did the same thing in Blizz-ABS Config, I was going to tell winkio to post that piece of code, but you already figured it out as I can see. xD

BTW, I like creating an actual identical copy using serialization.
Title: Re: [C#] Copying and Pasting Objects/Classes?
Post by: G_G on April 10, 2011, 08:31:59 am
Well see since its my own class I created my own clone method so isn't that pretty identical?
Title: Re: [C#] Copying and Pasting Objects/Classes?
Post by: Blizzard on April 10, 2011, 09:17:56 am
The thing with cloning using serialization is that it can be done in 3 lines of code. Even if your class has over 9000 variables, you just need those 3 lines for cloning.