Exemplo n.º 1
0
        public static Dictionary<string, string> GetPropertyValues(Settings settings)
        {
            var dictionary = new Dictionary<string, string>();

            var members = typeof(Settings).FindMembers(
                MemberTypes.Property,
                BindingFlags.Instance | BindingFlags.Public,
                HasAttribute,
                null);

            foreach (PropertyInfo member in members)
            {
                if (member == null ||
                    member.GetValue(settings) == null)
                {
                    dictionary.Add(member.Name, null);
                }
                else if (member.PropertyType == typeof(IReadOnlyDictionary<string, string>))
                {
                    dictionary.Add(member.Name, "Connection strings");
                    foreach (var item in (IReadOnlyDictionary<string, string>)member.GetValue(settings))
                    {
                        dictionary.Add(item.Key, item.Value);
                    }
                }
                else
                {
                    dictionary.Add(member.Name, member.GetValue(settings).ToString());
                }
            }

            return dictionary;
        }
Exemplo n.º 2
0
        private static Settings Initialize()
        {
            bool isDevMode = true; // Consider using an environment variable to indicate this
            if (isDevMode)
            {
                // Normally we'd load a file based on the username so each developer would get their own settings,
                // but for this example we'll specify the file name so everyone can see how this override works
                AppSettingsLoader.DevSettings = new DevSettingLoader(
                    dir: AppDomain.CurrentDomain.BaseDirectory,
                    fileName: "common.json");
            }

            var settings = new Settings();
            AppSettingsLoader.Load(Factory.GetAppConfigSettingLoader(), ref settings);

            return settings;
        }