internal bool TryGet(OptionKey key, out string propertyKey, out object value) { propertyKey = null; value = null; var type = key.Option.Type; var defaultValue = key.Option.DefaultValue; if (TryGetSerializationMethods <object> (type, out var serializer, out var deserializer)) { defaultValue = serializer(defaultValue); type = typeof(object); } // Check for roaming/profile properties foreach (var keyToCheck in key.GetPropertyNames()) { propertyKey = propertyKey ?? keyToCheck; value = value ?? defaultValue; if (keyToCheck == null) { continue; } if (PropertyService.HasValue(keyToCheck)) { value = PropertyService.GlobalInstance.Get(keyToCheck, defaultValue, type); return(true); } } return(propertyKey != null); }
public void TestRoslynPropertyWithMultipleKeys() { var(preferences, persister) = Setup(); var option = new PerLanguageOption <bool> ("test", "name", false, new RoamingProfileStorageLocation("feature.%LANGUAGE%.test"), new RoamingProfileStorageLocation("feature.test")); var optionKey = new OptionKey(option, LanguageNames.CSharp); var propertyNames = optionKey.GetPropertyNames().ToArray(); Assert.AreEqual(2, propertyNames.Length); Assert.AreEqual("feature.CSharp.test", propertyNames [0]); Assert.AreEqual("feature.test", propertyNames [1]); PropertyService.Set(propertyNames [1], true); var success = persister.TryFetch(optionKey, out object value); Assert.AreEqual(true, success); Assert.AreEqual(true, value); }