質問

誰もがINotifyCollectionChangedを実装する.Netのジェネリックキューのバージョンを書いたのですか、それとも.Netフレームワークのどこかにすでに隠されているものはありますか?

役に立ちましたか?

解決

クイック検索で結果が表示されませんでした。しかし、インターフェースはシンプルであり、Queueクラスを拡張し、インターフェースのサポートを追加することはほとんど簡単です。このようにすべてのメソッドをオーバーライドするだけです:

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

他のヒント

Chris Wenhamと同じアプローチを使用しました。エンキュー/デキューごとに新しいNotifyCollectionChangedEventArgsを割り当てる必要があるため、負荷がかかるとパフォーマンスが低下します。

とにかく、エンキューで、NotifyCollectionChangedAction.Add、追加されたアイテム、およびインデックスとしてCount-1を使用して引数を送信します。デキューで、NotifyCollectionChangedAction.Remove、削除されたアイテム、およびインデックス0で引数を送信します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top