title: Returning specific repository by interface
body: <p>I have following structure of code as below. I have currently two repository classes which both implements so far one generic interface with single method. They only pass diffrent return type object. I also have Factory pattern class to retreive specific repository. My problem is in my RepositoryFactory i get error message shown below. To be honest i have no idea what should be done. Counting on your support.</p>
  
  <p><strong>Errors:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/gNy0m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gNy0m.png" alt="enter image description here"></a></p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>public interface IRepository&lt;T&gt; where T :class 
  {
     IEnumerable&lt;T&gt; GetRecords();
  }
  
  public class CsvRepository : IRepository&lt;InputData&gt;
  {
  
     private string _path;
  
     public CsvRepository(string path)
     {
         _path = path;
     }
  
     public IEnumerable&lt;IBasic&gt; GetRecords()
     {
         return from line in File.ReadLines(_path)
                select line.Split(',') into parts
                where parts.Length == 3
                select new InputData { Name = parts[0], X = Convert.ToInt32(parts[1]), Y = Convert.ToInt32(parts[2]) };
      }
  }
  
  //other repositories:
  public class OracleRepository : IRepository&lt;OtherDataType&gt;
  {
  ..
  }
  ...
  
  
  //Factory pattern to get specific repository on demand
  //Implement IoC later on (register instead of cases)
  public class RepositoryFactory
  {
     public static IRepository GetRepository(DataSource repositoryType)
     {
        IRepository repo;
        switch (repositoryType)
        {       
           //break;
           case DataSource.Csv:
                repo = new CsvRepository("path"); //perhaps path shoudln't br right passed right here - so where?
                break;
           case DataSource.Oracle:
                repo = new OracleRepository();
                break;
           default:
                throw new ArgumentException("Invalid Repository Type");
        }
  
     return repo;
     }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong>
  I was trying to just make simpler - non generic interface on top of my current one like this:</p>
  
  <pre><code>  public enum DataSource
      {
          SqlServer,
          Csv,
          Oracle
      }
    public interface IRepo
      {
      }
  </code></pre>
  
  <p>so:</p>
  
  <pre><code>public interface IRepository&lt;T&gt; : IRepo
  </code></pre>
  
  <p>then i tried:</p>
  
  <pre><code>public static IRepo GetRepository(DataSource repositoryType)
          {
              IRepo repo;
  
              switch (repositoryType)
              {
                  //case "Service":
                  //    repo = new ServiceRepository();
                  //    break;
                  case DataSource.Csv:
                      repo = new CsvRepository("path"); //perhaps path shoudln't br right passed right here - so where?
                      break;
                  case DataSource.SqlServer:
                      repo = new SqlRepository();
                      break;
                  default:
                      throw new ArgumentException("Invalid Repository Type");
              }
  
              return repo;
          }
  </code></pre>
  
  <p>however then i get errors:</p>
  
  <pre><code>Cannot implicitly convert type 'CsvRepository' to 'IRepo'. An explicit conversion exists (are you missing a cast?)  
  Cannot implicitly convert type 'SqlRepository' to 'IRepo'. An explicit conversion exists (are you missing a cast?)  
  </code></pre>