I am trying to implement generic class using code below:
interface IBasicInput<T> where T : InputOutputConfig
{
void Configure<T>(ConfigurationDictionary<T> conf) where T : InputOutputConfig;
}
public class ConfigurationDictionary<T> : Dictionary<string,T> where T : InputOutputConfig
{
}
public abstract class InputOutputConfig
{
}
public class SpecificInputConfig : InputOutputConfig
{
}
public class GenericInput<T> : IBasicInput<T> where T : InputOutputConfig
{
ConfigurationDictionary<T> configuration;
public GenericInput()
{
configuration = null;
}
public void Configure<T>(ConfigurationDictionary<T> _conf) where T : InputOutputConfig
{
configuration = new ConfigurationDictionary<T>();
foreach (KeyValuePair<string,T> kvp in _conf)
{
}
}
}
The isssue is that configuration = new ConfigurationDictionary<T>();
generates error.
Error CS0029 Cannot implicitly convert type 'ConfigurationDictionary [GenericsTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]' to 'ConfigurationDictionary [GenericsTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]'
This message does not make sense to me since it basicly says it cannot convert "typeA" to "typeA". Could someone explain what is wrong with this code?
T
within the scope of yourConfigure
method – jamespconnor