public bool Merge(object source, IServiceProvider services) { MergeableObject mSource = source as MergeableObject; if (mSource != null) { Property += mSource.Property; return(true); } return(false); }
public void ReplaceExistingTryMerge() { object key = new object(); SharedDictionaryImpl source = new SharedDictionaryImpl(SharedDicTestContext.ServiceProvider); source[this, SharedDicTestContext.Plugins[0], "key1"] = "value1"; source[this, SharedDicTestContext.Plugins[0], "key2"] = "value2"; source[this, SharedDicTestContext.Plugins[0], "key3"] = "value3"; source[this, SharedDicTestContext.Plugins[0], "key4"] = "newValue"; MergeableObject mergeableObj = new MergeableObject() { Property = 10 }; source[key, SharedDicTestContext.Plugins[1], "mergeableObject"] = mergeableObj; SharedDictionaryImpl target = new SharedDictionaryImpl(null); MergeableObject newMergeableObj = new MergeableObject() { Property = 20 }; target[key, SharedDicTestContext.Plugins[1], "mergeableObject"] = newMergeableObj; target[this, SharedDicTestContext.Plugins[0], "key4"] = "value4"; target.Import(source, MergeMode.ReplaceExistingTryMerge); Assert.That(((MergeableObject)target[key, SharedDicTestContext.Plugins[1], "mergeableObject"]).GetHashCode() == newMergeableObj.GetHashCode()); Assert.That(((MergeableObject)target[key, SharedDicTestContext.Plugins[1], "mergeableObject"]).Property == 30); Assert.That((string)target[this, SharedDicTestContext.Plugins[0], "key1"] == "value1"); Assert.That((string)target[this, SharedDicTestContext.Plugins[0], "key2"] == "value2"); Assert.That((string)target[this, SharedDicTestContext.Plugins[0], "key3"] == "value3"); Assert.That((string)target[this, SharedDicTestContext.Plugins[0], "key4"] == "newValue"); }
public void ReplaceExistingTryMerge() { object key = new object(); SharedDictionaryImpl source = new SharedDictionaryImpl( SharedDicTestContext.ServiceProvider ); source[this, SharedDicTestContext.Plugins[0], "key1"] = "value1"; source[this, SharedDicTestContext.Plugins[0], "key2"] = "value2"; source[this, SharedDicTestContext.Plugins[0], "key3"] = "value3"; source[this, SharedDicTestContext.Plugins[0], "key4"] = "newValue"; MergeableObject mergeableObj = new MergeableObject() { Property = 10 }; source[key, SharedDicTestContext.Plugins[1], "mergeableObject"] = mergeableObj; SharedDictionaryImpl target = new SharedDictionaryImpl( null ); MergeableObject newMergeableObj = new MergeableObject() { Property = 20 }; target[key, SharedDicTestContext.Plugins[1], "mergeableObject"] = newMergeableObj; target[this, SharedDicTestContext.Plugins[0], "key4"] = "value4"; target.Import( source, MergeMode.ReplaceExistingTryMerge ); Assert.That( ((MergeableObject)target[key, SharedDicTestContext.Plugins[1], "mergeableObject"]).GetHashCode() == newMergeableObj.GetHashCode() ); Assert.That( ((MergeableObject)target[key, SharedDicTestContext.Plugins[1], "mergeableObject"]).Property == 30 ); Assert.That( (string)target[this, SharedDicTestContext.Plugins[0], "key1"] == "value1" ); Assert.That( (string)target[this, SharedDicTestContext.Plugins[0], "key2"] == "value2" ); Assert.That( (string)target[this, SharedDicTestContext.Plugins[0], "key3"] == "value3" ); Assert.That( (string)target[this, SharedDicTestContext.Plugins[0], "key4"] == "newValue" ); }