可观察队列? [英] ObservableQueue?

查看:31
本文介绍了可观察队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人编写过实现 INotifyCollectionChanged 的​​ .Net 通用队列版本,或者是否已经在 .Net 框架深处某个地方隐藏了一个?

Has anyone written a version of .Net's generic Queue that implements INotifyCollectionChanged, or is there one hidden deep in the .Net framework somewhere already?

推荐答案

快速搜索没有显示任何结果.但是接口很简单,扩展 Queue 类并添加对接口的支持几乎是微不足道的.只需重写所有方法:

A quick search didn't show any results. But the interface is simple and it would be almost trivial to extend the Queue class and add support for the interface. Just override all methods thusly:

// this isn't the best code ever; refactor as desired
protected void OnCollectionChanged( NotifyCollectionChangedEventArgs ccea){
  var temp = CollectionChanged;
  if(temp != null) temp(this, ccea);  
}

// and later in the class

public override SomeMethodThatAltersTheQueue(object something){
  // record state of collection prior to change
  base.SomeMethodThatAltersTheQueue(something)
  // create NotifyCollectionChangedEventArgs with prior state and new state
  OnCollectionChanged(ccea);
}

这篇关于可观察队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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