Q:

Factory of classes implementing interfaces with generic types in C#?

I need to create a general way of handling files. Depending on what needs to be done with the file, specific classes should be used. I use ASP and C#. File is uploaded, I analyze the file, create an analysis result object and show analysis results basing on that object to the user. User reads analysis result and proceeds (clicks a button) or not. If he does than I take that analysis result object and perform an action (processing) based on it. I show the results of the processing to the user.
Depending on some query parameters (for sake of simplicity) the file should be processed by different classes. The processor needs analysis result specific for the concrete implementation of the analyzer (result of analyzing one file might inclde list of custom classes, result of different file analysis might contain other specific fields). The processor needs those implementation-specific details to do it's job.
I made an attempt to create general project but am stuck.
The magicId in the factory is a query parameter specifying which class should be used to parse/analyze the file.
Is there a way to create a working factory of classes, which all implement a genericly-typed interface?
abstract class AnalysisResult
{
}

interface IAnalyzer<TAnalysisResult>
    where TAnalysisResult : AnalysisResult
{
    TAnalysisResult PerformAction(string input);
}

class ConcreteAnalysisResult : AnalysisResult {
    public int SpecificProperty { get; set; }
}

class ConcreteAnalyzer : IAnalyzer<ConcreteAnalysisResult>
{
    public ConcreteAnalysisResult PerformAction(string input)
    {
        return new ConcreteAnalysisResult() { SpecificProperty = input.Length };
    }
}

class AnAnalyzerFactory
{
    IAnalyzer<AnalysisResult> CreateByMagicId(int magicId)
    {
        return new ConcreteAnalyzer();
    }
}

A:

Declare TAnalysisResult as covariant. For details you can check Covariance and Contravariance
interface IAnalyzer<out TAnalysisResult> // note out keyword
    where TAnalysisResult : AnalysisResult
{
    TAnalysisResult PerformAction(string input);
}

