I'm trying to make a generic class that takes 3 types, either a simple string, IList<string>
or a IList<OntologyStore>
.
public class OntologyStore
{
}
public sealed class jim<T> where T:new()
{
string J;
IList<string> X = null;
IList<OntologyStore> X1 = null;
public jim()
{
if (typeof(T) == typeof(String))
{
J = string.Empty;
}
if (typeof(T) == typeof(OntologyStore))
{
X1 = new List<OntologyStore>();
}
if (typeof(T)==typeof(IList))
{
X = new List<string>();
}
}
}
I can easily create, which you would expect to work,
jim<OntologyStore> x1=new jim<jim<OntologyStore>()
as you would expect, but when I put in
jim<string> x2=new jim<string>()
the compiler reports the string is non abtract type, which you would expect.
Is it possible to create a generic class, which can instantiate as a class which holds string, or a IList<string>
or an IList<OntologyStore>
?