简体   繁体   中英

Copy object using Clipboard and paste it as object or text

I want to copy object ( List ) to clipboard and use it in my application and outside of it. In my application, I want to be able to "paste" data without any additional operation. Outside I need CSV data.

I tried to achieve it by using DataObject. I can convert this list to formatted string - so i think it's easy to get CSV. I stored random string in DataObject, (just for test). The problem is storing List object in Clipboard. DataObject contains specific type ( checked using DataObject.GetFormats() ), but when i try to get this object from clipboard, I get null.

I've found this , while it solves my problem, I need to serialize/deserialize.

Is there any way to store and retrieve object the normal way ?

Clipboard.SetDataObject(list);
var deslist = Clipboard.GetDataObject().GetData(list.GetType());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM