public void AsReadOnly() { PropertyBag original = new PropertyBag(); original.Add("abc", "123"); PropertyBag readOnly = original.AsReadOnly(); Assert.IsTrue(readOnly.IsReadOnly); AssertAreEqual(original, readOnly); MbUnit.Framework.Assert.Throws <NotSupportedException>(delegate { readOnly.Add("def", "456"); }); MbUnit.Framework.Assert.Throws <NotSupportedException>(delegate { readOnly["abc"].Add("456"); }); }
public ChangeSet Capture() { if (Leakage != null || Admixture != null || Changes != null) throw new NotSupportedException("Cannot call this method twice."); NewVersion = Get().AsReadOnly(); Admixture = new PropertyBag(); Changes = new PropertyBag(); Leakage = new PropertyBag(); foreach(var key in BaseLine.Keys.Union(NewVersion.Keys)) { if (BaseLine.ContainsKey(key) && NewVersion.ContainsKey(key)) { var bval = BaseLine[key]; var cval = NewVersion[key]; if (!Equals(bval, cval)) { Changes.Add(key, cval); } } else if (BaseLine.ContainsKey(key) && !NewVersion.ContainsKey(key)) { Leakage.Add(key, BaseLine[key]); } else if (!BaseLine.ContainsKey(key) && NewVersion.ContainsKey(key)) { Admixture.Add(key, NewVersion[key]); } } Admixture = Admixture.AsReadOnly(); Changes = Changes.AsReadOnly(); Leakage = Leakage.AsReadOnly(); return this; }
public void AsReadOnly() { PropertyBag original = new PropertyBag(); original.Add("abc", "123"); PropertyBag readOnly = original.AsReadOnly(); Assert.IsTrue(readOnly.IsReadOnly); AssertAreEqual(original, readOnly); MbUnit.Framework.Assert.Throws<NotSupportedException>(delegate { readOnly.Add("def", "456"); }); MbUnit.Framework.Assert.Throws<NotSupportedException>(delegate { readOnly["abc"].Add("456"); }); }