This will not work in your situation. You can only specify the constraint that it has an empty constructor:
public static string GetAllItems<T>(...) where T: new()
What you could do is use property injection by defining this interface:
public interface ITakesAListItem
{
ListItem Item { set; }
}
Then you could alter your method to be this:
public static string GetAllItems<T>(...) where T : ITakesAListItem, new()
{
...
List<T> tabListItems = new List<T>();
foreach (ListItem listItem in listCollection)
{
tabListItems.Add(new T() { Item = listItem });
}
...
}
The other alternative is the Func
method described by JaredPar.