I've got a number of classes that inherit from Item<T>
.
Each class has a Create() method that I would like to move up into Item<T>
.
Yet the following code gets the error "Cannot create an instance of the variable type 'T' because it does not have the new() constraint":
T item = new T(loadCode);
What is the correction syntax to do this?
public abstract class Item<T> : ItemBase
{
public static T Create(string loadCode)
{
T item = new T(loadCode);
if (!item.IsEmpty())
{
return item;
}
else
{
throw new CannotInstantiateException();
}
}