title: Creating a Generic Field in a Class
body: <p>I'm writing a file processing service to parse and process different kinds of transaction files. I have a generic file parser with implementations for different types of transactions as follows. </p>
  
  <pre><code>public interface IFileParser&lt;T&gt; 
  {
     List&lt;T&gt; Parse(StreamReader fileStream);
  }
  
  public MonthlyParser : IFileParser&lt;MonthlyTransaction&gt;
  {
       public List&lt;MonthlyTransaction&gt; Parse(StreamReader fileStream)
       {
         ......
       }
  }
  
  public DailyParser : IFileParser&lt;DailyTransaction&gt;
  {
       public List&lt;DailyTransaction&gt; Parse(StreamReader fileStream)
       {
           .....
       }
  }
  
  public enum FileTypes
  {
     DailyTransaction,
     MonthlyTransaction
  }
  
  public class FileProcessor
  {
      private TransactionContext dataContext;
      private IFileParser&lt;T&gt; fileParser;
  
      public FileProcessor(TransactionContext dbContext)
      {
          dataContext = dbContext;   
      }
  
      public void ProcessFile(string filePath, FileType fileType)
      {
         // here instantiate IFileParser based on FileType.
         // parse and process file.
      }
  
  }
  </code></pre>
  
  <p>My problem is how do I create a field in the FileProcessor class of that generic interface to which a concrete implemenation can be assigned and used? Im also thinking of moving the instantiation to an IoC.</p>