[C#] Copying and Pasting Objects/Classes?

Started by G_G, April 09, 2011, 06:16:53 pm

Previous topic - Next topic

G_G

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.

Ryex

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.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

winkio

you can extend the clipboard to hold different types of objects.

Ryex

I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

G_G


Blizzard

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.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Well see since its my own class I created my own clone method so isn't that pretty identical?

Blizzard

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.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.