Beispiel #1
0
        /// <summary>
        /// Reads value from settings.
        /// </summary>
        /// <typeparam name="T"><see cref="System.Type"/> parameter to read.</typeparam>
        /// <param name="key">Setting key to read.</param>
        /// <param name="composite">Setting composite to read.</param>
        /// <returns>Setting value.</returns>
        private static T ReadSettingValue <T>(string key, string composite = null)
        {
            SetVersion(); // Ensure settings are on last version
            T      loSettingValue = default(T);
            object loValue        = null;

#if WINDOWS_UWP
            ApplicationDataContainer      loRoamingSettings = ApplicationData.Current.RoamingSettings;
            ApplicationDataCompositeValue loComposite       = null;
            if (!string.IsNullOrEmpty(composite))
            {
                loComposite = loRoamingSettings.Values[composite] as ApplicationDataCompositeValue;
                if (loComposite != null)
                {
                    if (!string.IsNullOrEmpty(key))
                    {
                        loValue = loComposite[key];
                    }
                    else
                    {
                        if (typeof(T) == typeof(MSHealthToken))
                        {
                            loValue = loComposite.ToMSHealthToken();
                        }
                    }
                }
            }
            else
            {
                loValue = loRoamingSettings.Values[key];
            }
#elif DESKTOP_APP
            loValue = ConfigurationManager.AppSettings[key];
#endif
            if (loValue != null)
            {
                loSettingValue = (T)loValue;
            }
            return(loSettingValue);
        }