0

我想将下面的数据透视函数的结果提取到 csv V 文件中。有谁知道如何以更通用的方式完成此操作而无需编写大量手动代码?在这个阶段,库的名称并不重要,但如果也可以通过从预加载的数组或列表等中读取来动态设置库,那可能会很好......

非常感谢提前 M

public static Dictionary<TKey1,   Dictionary<TKey2,Dictionary<TKey3,Dictionary<TKey4,TValue>>>> PivotLinq<TSource, TKey1, TKey2,TKey3,TKey4, TValue>(
this IEnumerable<TSource> source, Func<TSource, TKey1> key1Selector, Func<TSource, TKey2> key2Selector, Func<TSource, TKey3> key3Selector, Func<TSource, TKey4> key4Selector,
   Func<IEnumerable<TSource>, TValue> aggregate)
    {
        return source.GroupBy(key1Selector).Select(
        x => new
        {
            X = x.Key,
            Y = x.GroupBy(key2Selector).Select(
            z => new
            {
                Z = z.Key,
                V =z.GroupBy(key3Selector).Select( 
                 w => new 
                 {
                     W=w.Key ,
                     B = w.GroupBy(key4Selector).Select(
                      c=> new 
                      {
                          C=c.Key ,
                          D=aggregate(c)
                      }).ToDictionary(e=>e.C, o=>o.D)
                 }
                      ).ToDictionary(e=>e.W, o=>o.B)
            }
                 ).ToDictionary(e=>e.Z , o=>o.V  )
            }).ToDictionary(e=>e.X,o=>o.Y);

        }
4

0 回答 0