Failed to create interface for my class using refactoring in VS2010

I have the following class, and I'm trying to create an interface for this. However, when I try to refactor in VS2010. I get a message that: Failed to retrieve. The type does not contain members that can be retrieved in the interface.

Is this related to my definition of a class and / or method as static? What I need to be able to get this data without creating an instance so that 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" } }; } 

}

+4
source share
2 answers

You cannot have a static class with an interface, so the refactoring tool cannot retrieve it. You will need to turn it into an instance class with instance members in order to extract the interface.

+4
source

You have no methods that could be learned. static methods cannot belong to an interface.

Google for the static interface method , and you will get interesting articles such as http://discuss.joelonsoftware.com/default.asp?dotnet.12.305680.12

+4
source

Source: https://habr.com/ru/post/1385828/


All Articles