You could use a covariant interface for ShaderParam<T>
:
interface IShaderParam<out T> { ... }
class ShaderParam<T> : IShaderParam<T> { ... }
Usage:
IShaderParam<object>[] parameters = new IShaderParam<object>[5];
parameters[0] = new ShaderParam<string>(); // <- note the string!
But you can't use it with value types like float
in your example. Covariance is only valid with reference types (like string
in my example). You also can't use it if the type parameter appears in contravariant positions, e.g. as method parameters. Still, it might be good to know about this technique.