Saturday, 17 August 2013

ObservableCollection passed as paramater and Interfaces

ObservableCollection passed as paramater and Interfaces

I have an interface IPerson and two classes, Adventurer and Worker that
implement it. I currently have separate ObservableCollections for
Adventurers and Workers. I have a method that I would like to be able to
pass both an ObservableCollection<Adventurer> and an
ObservableCollection<Worker> to as a parameter and so far I haven't had
any luck. The method uses only properties implemented in IPerson and if I
declare it as:
public void MyMethod(ObservableCollection<IPerson> collection)
...there are no errors inside the method itself. However, when I try to
pass in an ObservableCollection<Adventurer>, I get 2 errors:
Cannot convert from
'System.Collections.ObjectModel.ObservableCollection<AoW.Models.Adventurer>'
to
'System.Collections.ObjectModel.ObservableCollection<AoW.Models.IPerson>'
and
The best overloaded method match for
'AoW.MyMethod(System.Collections.ObjectModel.ObservableCollection<AoW.Models.IPerson>)'
has some invalid arguments
Is it possible for me to pass both ObservableCollections to the same
method? If so, how should I go about it? Any advice would be greatly
appreciated.

No comments:

Post a Comment