In order to explain the problem I've created a simplified example. In real life the data class is somewhat more complicated. Consider the following data class:
public class Data
{
public Data(string source, string path, string information)
{
this.Source = source;
this.Path = path;
this.Information = information;
}
public string Source { get; set; }
public string Path { get; set; }
public string Information { get; set; }
}
Now consider the following array:
var array = new Data[] {
new Data("MS", @"c:\temp\img1.jpg", "{a}"),
new Data("IBM", @"c:\temp\img3.jpg", "{b}"),
new Data("Google", @"c:\temp\img1.jpg", "{c}"),
new Data("MS", @"c:\temp\img2.jpg", "{d}"),
new Data("MS", @"c:\temp\img3.jpg", "{e}"),
new Data("Google", @"c:\temp\img1.jpg", "{f}"),
new Data("IBM", @"c:\temp\img2.jpg", "{g}")
};
I would like to process the data by partitioning it on the Path and sorting each partition on Source. The output needs to be like:
c:\temp\img1.jpg
"Google": "{c}"
"IBM": "{f}"
"MS": "{a}"
c:\temp\img2.jpg
"IBM": "{g}"
"MS": "{d}"
c:\temp\img3.jpg
"IBM": "{b}"
"MS": "{e}
How can I create these partitions with LINQ?
Here you can play with the code: https://dotnetfiddle.net/EbKluE