对于IGrouping实现类是什么? [英] What is the implementing class for IGrouping?

查看:563
本文介绍了对于IGrouping实现类是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个WCF数据服务ServiceOperation,它在服务器端进行分组,然后将数据发送到客户端。

I am trying create a WCF Data Services ServiceOperation that does grouping on the server side and then sends the data down to the client.

当我尝试调用它(甚至连接到服务),我得到一个错误。它说,它无法构造一个接口。

When I try to call it (or even connect to the service) I get an error. It says that it can't construct an interface.

我使用的唯一接口是IGrouping。

The only interface I am using is IGrouping.

什么是A /实际的类为这个接口?

What is a/the actual class for this interface?

更新:

我检查类型在调试一个示例应用程序,它告诉我,它是:

I checked the type while debugging a sample app and it told me it was:

System.Linq.Lookup<TKey,TElement>.Grouping

但是,什么组件是哪个?

But what assembly is it in?

推荐答案

若干类型的BCL实施 IGrouping ,但他们都是内置的,不能只是通过访问 IGrouping 接口。

Several types in the BCL implement IGrouping, however they are all internal and cannot be accessed except by the IGrouping interface.

但是,一个 IGrouping 只是一个的IEnumerable&LT; TElement&GT; 与相关联的密钥。您可以轻松地实施 IGrouping 是由名单,其中支持; TElement&GT; 键,这不应该是很难跨越序列化一个呼叫界限:

But an IGrouping is merely an IEnumerable<TElement> with an associated key. You can easily implement an IGrouping that is backed by a List<TElement> and that should not be hard to serialize across a call boundary:

public class Grouping<TKey, TElement> : IGrouping<TKey, TElement> {

  readonly List<TElement> elements;

  public Grouping(IGrouping<TKey, TElement> grouping) {
    if (grouping == null)
      throw new ArgumentNullException("grouping");
    Key = grouping.Key;
    elements = grouping.ToList();
  }

  public TKey Key { get; private set; }

  public IEnumerator<TElement> GetEnumerator() {
    return this.elements.GetEnumerator();
  }

  IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }

}

应用 GROUPBY 运营商后,您可以创建分组实例列表:

After applying the GroupBy operator you can create a list of Grouping instances:

var listOfGroups =
  source.GroupBy(x => ...).Select(g => new Grouping<TKey, TElement>(g)).ToList();

这篇关于对于IGrouping实现类是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆