I have my base interface class:
public interface IAlgorithm<T> where T : IParams
{
/// <summary>
/// Contains algorythm parameters
/// </summary>
T Params{ get; set; }
}
And
public interface IParams
{
}
Then I have my basic class for algorithm implementation:
public abstract class BaseAlgorithm<T> : IAlgorithm<T> where T: IParams
{
public virtual T Params { get; set; }
}
public class DataAlgorithm : BaseAlgorithm<IDataParams>
{
public override IDataParams Params { get; set; }
}
And params:
public interface IDataParams : IParams
{
}
There are multiple of BaseAlgorithm
class implementations.
Now I want to create new isntance of DataAlgorith
and assign it to the parent interface:
IAlgorithm<IParams> algorithm = new DataAlgorithm();
but it wont work and produces error message:
Cannot implicitly convert type 'DataAlgorithm' to 'IAlgorithm<IParams>'. An explicit conversion exists (are you missing a cast?)
The code below will work just fine:
IAlgorithm<IDataParams> algorithm = new DataAlgorithm();
Any ideas how to assign to parent type?