为什么这个对象总是从剪贴板返回为空
我正在使用 .net 中的剪贴板,使用以下代码
List<object> templateList = new List<object>();
Clipboard.Clear();
Clipboard.SetDataObject(templateList);
IDataObject dataObject = Clipboard.GetDataObject();
var x = (List<object>)dataObject.GetData(typeof(List<object>));
对于上面的代码 x 是一个空的对象列表,正如您所期望的那样,
如果我将代码更改为
List<Template> templateList = new List<Template>();
Clipboard.Clear();
Clipboard.SetDataObject(templateList);
IDataObject dataObject = Clipboard.GetDataObject();
var x = (List<Template>)dataObject.GetData(typeof(List<Template>));
x 现在为空,
模板的类既是公共的又是可序列化的,并且应用程序在 STAthread 上运行
有什么想法吗?
I am working with the clipboard in .net with the following code
List<object> templateList = new List<object>();
Clipboard.Clear();
Clipboard.SetDataObject(templateList);
IDataObject dataObject = Clipboard.GetDataObject();
var x = (List<object>)dataObject.GetData(typeof(List<object>));
For the above code x is an empty List of objects as you would expect
if i change the code to be
List<Template> templateList = new List<Template>();
Clipboard.Clear();
Clipboard.SetDataObject(templateList);
IDataObject dataObject = Clipboard.GetDataObject();
var x = (List<Template>)dataObject.GetData(typeof(List<Template>));
x is now null
the class for Template is both public and Serializable and the application is running on a STAthread
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Template 是否有任何未标记为可序列化的对象属性?
换句话说,即使 Template 被标记为可序列化,您是否确实尝试过序列化它以确认其有效?
Does Template have any object properties that are not marked as serializable?
In other words, even though Template is marked as serializable have you actually tried to serialize it, to confirm this works?