|
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
namespace DiagnosticExplorer.Silverlight
{
public class DiagBag
{
private const StringComparison _ignoreCase = StringComparison.CurrentCultureIgnoreCase;
public event PropertyChangedEventHandler PropertyChanged;
public ObservableCollection<DiagSubBag> SubBags { get; private set; }
public string Name { get; private set; }
public DiagBag(string name)
{
Name = name;
SubBags = new ObservableCollection<DiagSubBag>();
}
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public DiagSubBag FindSubBag(string name, bool createIfNotFound)
{
DiagSubBag bag = SubBags.FirstOrDefault(b => string.Equals(b.Name, name, _ignoreCase));
if (bag == null && createIfNotFound)
{
bag = new DiagSubBag(name);
SubBags.Add(bag);
}
return bag;
}
public void Merge(DiagBag bag2)
{
foreach (DiagSubBag subbag in bag2.SubBags)
FindSubBag(subbag.Name, true).Merge(subbag);
for (int i = SubBags.Count - 1; i >= 0; i--)
if (bag2.FindSubBag(SubBags[i].Name, false) == null)
SubBags.RemoveAt(i);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am a software developer originally from Auckland, New Zealand. I have lived and worked in London since 2005.