【发布时间】:2014-11-19 05:55:12
【问题描述】:
我正在尝试像这样为剪贴板创建一个新的方法扩展,但是当我使用它时,扩展“GetDataThread”永远不会出现在可用列表中,如果我仍然输入它会返回错误。
using System.Windows.Forms;
namespace MyProject.ClipboardManager.Extensions
{
public static class ClipboardExtensions
{
public static string GetDataThread(this Clipboard clip)
{
var selectedOption = string.Empty;
Thread t = new Thread(() =>
{
selectedOption = (string)Clipboard.GetData(DataFormats.Text);
});
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
return selectedOption;
}
}
}
我是这样称呼它的:
using System.Windows.Forms;
using MyProject.ClipboardManager.Extensions;
...
content = Clipboard.GetDataThread();
这里的错误是:“System.Windows.Forms.Clipboard 不包含 GetDataThread 的定义..
所以我不确定我在这里做错了什么......
【问题讨论】:
-
您不能创建剪贴板类(it has private constructor) 的实例,您只能使用类实例的扩展方法。因此,您无法实现您想要做的事情
标签: c# extension-methods