C# Func<> and generics -
So, I am doing a bit out of my comfort zone when working with the function of> lt;>, generics And lambda expressions but I guess. I normally look (like), but still a bit confused
I took SortableObservableCollection class (online anywhere! - thank whoever it is implemented to do was get it) And it is used like this:
_lookuplistViewModel.Sort (x => x.brandName, ListSortDirection.Ascending);
Where the object type is implemented by a sorted archive. In this example, a property of type Brandnam object, but I want to use in a general category to the above address and to sort the property is sort method looks like this:
Public Zero Sort & lt; TKey & gt; (Func & lt; T, TKey & gt; key selector, ListSortDirection direction) {switch (direction) {case ListSortDirection.Ascending: {ApplySort (Items .OrderBy (keySelector)); break; } Case Systems. CompanyModel.ListesDartDirectation Remittance: {Apply torrent (item order-ordered (key selector)); break; }}}
generic class is called Sort method on the thus defined:
public class ExtendedLookupManagerViewModel & LT; VMod, Mod & gt; : LookupManagerViewModel where VMod: ExtendedLookupViewModel where Mod: ExtendedLookupModelBase
And I want to make an example of it:
_medProd = new ExtendedLookupManagerViewModel & Lt; Medicinal Product View Model, Medicine Product & gt; (String property);
Where property
is the asset on which to sort it should ideally be safe, but a string will be sufficient.
Can anyone help me please correct direction?
Just match your constructor sig to the sig for the sort method, and sort Cache the parameters to be used in the collection when called. So whatever the sign is for the string method, but not the string property.
Passing parameters then have a function that can be specific and you can direct the elements, so immediately
_medProd = new ExtendedLookupManagerViewModel & LT; MedicinalProductViewModel, MedicinalProduct & gt; (X = & gt; x.brandName, ListSortDirection.Ascending);
Comments
Post a Comment