public void DeferredValueSharedTest() { string text = @" <test:DeferredDictionary xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests.Markup;assembly=Granular.Presentation.Tests'> <test:TestDictionaryValue x:Key='key1'/> <test:TestDictionaryValue x:Key='key2' x:Shared='false'/> </test:DeferredDictionary>"; DeferredDictionary dictionary = (DeferredDictionary)XamlLoader.Load(XamlParser.Parse(text)); Assert.IsTrue(dictionary.ContainsKey("key1")); Assert.IsTrue(dictionary.ContainsKey("key2")); ValueProvider valueProvider1 = dictionary["key1"] as ValueProvider; ValueProvider valueProvider2 = dictionary["key2"] as ValueProvider; Assert.IsNotNull(valueProvider1); Assert.IsNotNull(valueProvider2); TestDictionaryValue value1 = valueProvider1.ProvideValue() as TestDictionaryValue; TestDictionaryValue value2 = valueProvider2.ProvideValue() as TestDictionaryValue; Assert.IsNotNull(value1); Assert.IsNotNull(value2); TestDictionaryValue value1a = valueProvider1.ProvideValue() as TestDictionaryValue; TestDictionaryValue value2a = valueProvider2.ProvideValue() as TestDictionaryValue; Assert.IsTrue(ReferenceEquals(value1, value1a)); Assert.IsFalse(ReferenceEquals(value2, value2a)); }
public object GetValueKey(XamlElement element) { XamlMember keyMember = element.Members.SingleOrDefault(member => member.Name.LocalName == "Key"); if (keyMember != null) { object value = keyMember.Values.Single(); return(value is XamlElement?XamlLoader.Load((XamlElement)value) : value); } XamlMember partialKeyMember = element.Members.SingleOrDefault(member => member.Name.LocalName == "PartialKey"); if (partialKeyMember != null) { return(TestDictionaryValue.CreateKey(partialKeyMember.Values.Single().ToString())); } throw new Granular.Exception($"Can't create value key from \"{element.Name}\""); }