Since T
could in theory be any type, Visual Studio doesn't know if there's a way to cast from either type to T
. You could try inserting an (object)
cast:
itemList.Add(isFolder ? (T)(object)item.Folder : (T)(object)item);
As long as T
is the correct type, you should be fine.