Some of the answers/comments have mentioned
(ItemCollection)ItemManager.GetItems().Where(i => i.MyProperty).ToList()
which will not work because of up-casting. Instead, the above will produce a List<Item>
.
The following is what you will need to make these work. Note that you will need to have the ability to modify the ItemCollection
class in order for this to work.
Constructor
If you would like to make a constructor for the ItemCollection
class, then the following should work:
public ItemCollection(IEnumerable<Item> items) : base(items) {}
To call the constructor, you would then do the following:
var ic = new ItemCollection(ItemManager.GetItems().Where(i => i.MyProperty));
or
ItemCollection ic = new ItemCollection(ItemManager.GetItems().Where(i => i.MyProperty));
Note about the error message
In the comments, when asked to change ItemCollection ic = ItemManager.GetItems.....
to var ic = ItemManager.GetItems.....
and then tell us what the type of ic
is, you mentioned that you got Systems.Collections.Generic.List<T>
which would translate to List<Item>
. The error message that you received was actually not the error message that you should have received, which is likely just due to the IDE being confused, which occasionally happens when there are errors on the page. What you should have received is something more along the lines of:
Cannot implicitly convert type IEnumerable<Item> to ItemCollection.