rd0.MergedWith = typeof(MyRD);
object _;
- Assert.True(rd0.TryGetMergedValue("foo", out _));
+ Assert.True(rd0.TryGetValue("foo", out _));
Assert.AreEqual("Foo", _);
}
}
Assert.Fail();
}
+
+ [Test]
+ public void ContainsReturnsValuesForMergedRD()
+ {
+ var rd = new ResourceDictionary {
+ {"baz", "BAZ"},
+ {"qux", "QUX"},
+ };
+ rd.MergedWith = typeof(MyRD);
+
+ Assert.That(rd.Contains(new KeyValuePair<string, object>("foo", "Foo")), Is.True);
+ }
+
+ [Test]
+ public void CountDoesNotIncludeMerged()
+ {
+ var rd = new ResourceDictionary {
+ {"baz", "Baz"},
+ {"qux", "Qux"},
+ };
+ rd.MergedWith = typeof(MyRD);
+
+ Assert.That(rd.Count, Is.EqualTo(2));
+ }
+
+ [Test]
+ public void IndexerLookupInMerged()
+ {
+ var rd = new ResourceDictionary {
+ {"baz", "BAZ"},
+ {"qux", "QUX"},
+ };
+ rd.MergedWith = typeof(MyRD);
+
+ Assert.That(() => rd["foo"], Throws.Nothing);
+ Assert.That(rd["foo"], Is.EqualTo("Foo"));
+ }
+
+ [Test]
+ public void TryGetValueLookupInMerged()
+ {
+ var rd = new ResourceDictionary {
+ {"baz", "BAZ"},
+ {"qux", "QUX"},
+ };
+ rd.MergedWith = typeof(MyRD);
+
+ object _;
+ Assert.That(rd.TryGetValue("foo", out _), Is.True);
+ Assert.That(rd.TryGetValue("baz", out _), Is.True);
+}
}
}
\ No newline at end of file
bool ICollection<KeyValuePair<string, object>>.Contains(KeyValuePair<string, object> item)
{
- return ((ICollection<KeyValuePair<string, object>>)_innerDictionary).Contains(item);
+ return ((ICollection<KeyValuePair<string, object>>)_innerDictionary).Contains(item)
+ || (_mergedInstance != null && _mergedInstance.Contains(item));
}
void ICollection<KeyValuePair<string, object>>.CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
{
if (_innerDictionary.ContainsKey(index))
return _innerDictionary[index];
+ if (_mergedInstance != null && _mergedInstance.ContainsKey(index))
+ return _mergedInstance[index];
throw new KeyNotFoundException($"The resource '{index}' is not present in the dictionary.");
}
set
public bool TryGetValue(string key, out object value)
{
- return _innerDictionary.TryGetValue(key, out value);
- }
-
- internal bool TryGetMergedValue(string key, out object value)
- {
return _innerDictionary.TryGetValue(key, out value) || (_mergedInstance != null && _mergedInstance.TryGetValue(key, out value));
}
var resDict = ve?.Resources ?? p as ResourceDictionary;
if (resDict == null)
continue;
- if (resDict.TryGetMergedValue(Key, out resource))
+ if (resDict.TryGetValue(Key, out resource))
break;
}
resource = resource ?? GetApplicationLevelResource(Key, xmlLineInfo);
internal object GetApplicationLevelResource(string key, IXmlLineInfo xmlLineInfo)
{
object resource;
- if (Application.Current == null || Application.Current.Resources == null || !Application.Current.Resources.TryGetMergedValue(Key, out resource))
+ if (Application.Current == null || Application.Current.Resources == null || !Application.Current.Resources.TryGetValue(Key, out resource))
throw new XamlParseException($"StaticResource not found for key {Key}", xmlLineInfo);
return resource;
}