Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to create an interface for my class using refactor in VS2010

Tags:

c#

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" }
            };
    }

}

like image 885
Samantha J T Star Avatar asked Dec 16 '22 06:12

Samantha J T Star


2 Answers

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.

like image 72
Alex McBride Avatar answered Dec 22 '22 00:12

Alex McBride


You don't have any methods that could be extracted. static methods can't belong to an interface.

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

like image 33
Daniel Mošmondor Avatar answered Dec 22 '22 01:12

Daniel Mošmondor