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

问题描述

有没有人写了一个版本的.NET程序的通用队列实现INotifyCollectionChanged,或者是有一个在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?

推荐答案

一个快速搜索并没有表现出任何结果。但是,界面简洁,这将是几乎微不足道的扩展队列类,并添加支持的接口。刚刚覆盖所有方法正是如此:

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);
}

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

10-23 05:57