How can I write the below code with is T
public IList<IElement> OfClass(Type type)
{
return list
.Where(o => o.GetType() == type)
.ToList();
}
Something like this:
public IList<IEtabsElement> OfClass(....)
{
return list
.Where(o => o is ...)
.ToList();
}
UPDATE This is my solution, so far. Is it okay?
public IList<IElement> OfClass<T>()
{
return list
.Where(o => o is T)
.ToList();
}
You can create a generic method instead:
This would work, but is the same as the existing method
OfType
, for example: