I have something like this:
interface IArgument{ ... }
class ArgumentA : IArgument{ ... }
abstract class Parameter<T> where T : class, IArgument{
...
abstract decimal GetValue(T args);
...
}
class ParameterA : Parameter<ArgumentA>{
override decimal GetValue(ArgumentA args){
...
}
}
abstract class Calculation{
List<Parameter<IArgument>> Parameters{get;set;}
decimal FindParameterValue<T>() where T : Parameter<IArgument>{
...
}
}
The method FindParameterValue is where I have a problem. It gets the first parameter of a specific type out of the list and returns its value.
Now I get this error:
Error CS0311 The type 'ParameterA' cannot be used as type parameter 'T' in the generic type or method 'Calculation.FindParameterValue<T>()'. There is no implicit reference conversion from 'ParameterA' to 'Parameter<IArgument>'. .
I would like to just supply a derived class which implements Parameter< IArgument>.
I can avoid it by doing this:
public decimal FindParameterValue<T,U>() where T : Parameter<U> where U : class, IArgument
Which causes me to call it like:
FindParameterValue<ParameterA, ArgumentA>();
But I'd like to call it with just the 'ParameterA'-type.
Sorry if this is already solved somewhere.
Thanks in advance!