无法创建使用VS2010重构我的类的接口 [英] Unable to create an interface for my class using refactor in VS2010
问题描述
我有以下类,我试图创建一个这样的接口。
然而,当我试图在VS2010重构。我得到一个消息:无法
提取接口。类型不包含可能是提取到接口
任何成员。
I have the following class and I am trying to create an interface for this. However when I try refactor in VS2010. I get a message that: Could not extract interface. The type does not contain any members that could be extracted to an interface.
我定义的类和/或方法静态这是相关的?我
确实需要的是能够得到这个数据,而无需创建一个实例
所以这就是为什么我做这一切是静态的。
Is this related to my defining the class and/or method as static? What I do need is to be able to get this data without having to create an instance so that's why I made it all static.
public static class DataSourceService
{
public static IEnumerable<DataSource> GetDataSources()
{
return new[]
{
new DataSource { Value = "0001", Text = "Development" },
new DataSource { Value = "0002", Text = "Production" }
};
}
}
}
推荐答案
您不能有一个静态类,一个接口,这就是为什么重构工具,不能提取的。你需要把它变成一个实例类实例成员,以提取一个接口。
You cannot have a static class with an interface, that's why the refactor tool cannot extract one. You would need to turn it into an instance class with instance members in order to extract an interface.
这篇关于无法创建使用VS2010重构我的类的接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!