Splitting the data into different categories ("Cat", "Dog", "Default"). A function which does that may be called like this:
IEnumerable<T>[] categories = Categorize(items, new[]("Cat*", "Dog*", "*"));How you define and implement the prefix filter syntax is up to you and your specific needs, here I suggest to use a "*" as a placeholder for an arbitrary string. You can also use regular expressions here, if you need that.
Note usage of thisan array is just a simplified example, could be also a dictionary indexed by "Cat*", "Dog*", "*", or some other list of key-value pairs. Note also the order of the category filters is important, the order in which these filter steps have to be applied might be a different order than the one required in step 3.
Sorting the data in each category individually with an individual rule
categories[0] = categories[0].OrderBy(d=>d.Label); categories[1] = categories[1].OrderByDescending(d=>d.Label); categories[2] = categories[2].OrderBy(d=>d.Label);(you could also provide indidividual comparers here, or loop over all categories any apply different sorters, dependent from some other criteria).
Sorting the categories themselves (here "Default", "Cat", "Dog") and merge the data accordingly.
return categories[2].Concat(categories[0]).Concat(categories[1])(inI hardcoded this order because the example with 3 categories is very simple. In cases the category order follows a more complicated rule by itselfrules, this may require some more logic to sort, for example, by the category name, or some assigned priority) .