简体   繁体   English

ListAggregatorFactory 返回 system.collections.generic.list`1[system.object]

[英]ListAggregatorFactory returns system.collections.generic.list`1[system.object]

I've been using the powerful NReco library to create pivot tables.我一直在使用功能强大的 NReco 库创建 pivot 个表。 And using the very convenient HTML wrapper extension to turn those tables into HTML. When I use the '' I get the following returned into the HTML.并使用非常方便的 HTML 包装器扩展将这些表转换为 HTML。当我使用 '' 时,我将以下内容返回到 HTML。

System.Collections.Generic.List`1[System.Object] System.Collections.Generic.List`1[System.Object]

The error seems very straight-forward.该错误似乎非常简单。 The HTML wrapper is probably just calling ToString() on the collection object rather then joining the list. HTML 包装器可能只是在集合 object 上调用ToString()而不是加入列表。 Is there a way to override the HTML wrappers functionality when it comes to formatting this list.在格式化此列表时,有没有办法覆盖 HTML 包装器功能。

I assume you mean pivot table writers (like PivotTableHtmlWriter ) from NReco.PivotData.Extensions nuget package.我假设你的意思是来自 NReco.PivotData.Extensions nuget package 的 pivot 表编写器(如PivotTableHtmlWriter )。

You're right with your suggestion that by default aggregator's value is simply converted to string with object.ToString() call.您的建议是正确的,默认情况下聚合器的值只是通过object.ToString()调用转换为字符串。 This works good for simple values, however for complex objects (including lists) there are no default representation - this motivates to define your own 'value-formatter' handler and don't rely on any default conventions:这适用于简单的值,但是对于复杂的对象(包括列表)没有默认表示 - 这会激发您定义自己的“值格式化程序”处理程序并且不依赖任何默认约定:

pvtHtmlWr.FormatValue = (aggr,measureIdx) => {
  if (aggr.Count==0)
    return String.Empty;

  if (aggr.Value is IList) {
    var ls = (IList)aggr.Value;
    var sb = new StringBuilder();
    for (int i=0; i<ls.Count; i++) {
      var entryStr = Convert.ToString( ls[i] ); // or apply custom formatting of list entries
      if (entryStr.Length>0) {
        if (sb.Length>0)
          sb.Append(", ");
        sb.Append(entryStr);
      }
    }
    return sb.ToString();
  }

  // apply default number format
  return String.Format("{0:0.##}", aggr.Value); 
};

More on pivot table values formatting: https://www.nrecosite.com/pivotdata/format-pivot-table.aspx有关 pivot 表值格式的更多信息: https://www.nrecosite.com/pivotdata/format-pivot-table.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将类型为“System.Collections.Generic.List`1[System.Object]”的 object 转换为类型“System.Collections.Generic.List`1” - Unable to cast object of type 'System.Collections.Generic.List`1[System.Object]' to type 'System.Collections.Generic.List`1[customType] 列表内的列表不打印元素,而是显示System.Collections.Generic.List`1 [System.Object] - List inside list does not print elements, instead shows System.Collections.Generic.List`1[System.Object] 无法将 System.Collections.Generic.List[System.Object] 类型的对象转换为 System.Collections.Generic.IList[ShortCodeList] - Unable to cast object of type System.Collections.Generic.List[System.Object] to type System.Collections.Generic.IList[ShortCodeList] 键入“对象{System.Collections.Generic.List <T> }“ VS” System.Collections.Generic.List <T> ” - Type “object {System.Collections.Generic.List<T>}” VS “System.Collections.Generic.List<T>” 如何处理类型“ Object {System.Collections.Generic.List <object> }” - How to handle type “Object {System.Collections.Generic.List<object>}” 无法将类型&#39;object [] []&#39;转换为&#39;System.Collections.Generic.List <object> “ - Cannot convert type 'object[][]' to 'System.Collections.Generic.List<object>' 无法转换&#39;System.Collections.Generic.List`1类型的对象 - Unable to cast object of type 'System.Collections.Generic.List`1 system.collections.generic.list 到 system.collections.generic.ienumerable - system.collections.generic.list to system.collections.generic.ienumerable 无法将JSON对象反序列化为“System.Collections.Generic.List”类型 - Cannot deserialize JSON object into type 'System.Collections.Generic.List' 在System.Collections.Generic.List中的Find() <T> - Find() In a System.Collections.Generic.List<T>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM