Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I don't know why the method GetData() requires a parameter of Type, I thought the Type is to specify that of which class/type the object should be.
I have a structure called GraphicsPathWrap, it's made serializable by implementing ISerializable. I tried the following copy function:

C#
private void Copy(GraphicsPathWrap gpw){
  DataObject obj = new DataObject();
  obj.SetData(typeof(GraphicsPathWrap), gpw);
  Clipboard.SetDataObject(obj);
}


Then tried the following paste function:
C#
private GraphicsPathWrap Paste()
{
  return (GraphicsPathWrap)Clipboard.GetDataObject().GetData(typeof(GraphicsPathWrap));
}


It should work, but the GetData(...) returns an object of type MemoryStream and an InvalidCastException was thrown. I don't understand why it's type of MemoryStream. I thought it should be able to be casted to GraphicsPathWrap?
I can work around this by using a BinaryFormatter to deserialize the MemoryStream but it's too ridiculous when Clipboard can't do all the thing for me?

Thanks!
Posted
Updated 7-Mar-13 19:14pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900