예제 #1
0
        private static void LoadSettings()
        {
            IEnumerable <MethodInfo> methodInfos = TypeFinder.FindAllAttributes <OptionsSetting>();

            _settings = methodInfos.ToList();

            UserPreferences.Clear();
            foreach (MethodInfo setting in _settings)
            {
                try
                {
                    if (!TryGetAttribute(setting, out OptionsSetting attr))
                    {
                        continue;
                    }
                    if (UserPreferences.ContainsKey(attr.Name.ToLower()))
                    {
                        continue;
                    }

                    string defaultValue = attr.DefaultValue != null?attr.DefaultValue.ToString() : string.Empty;

                    if (!string.IsNullOrWhiteSpace(attr.defaultValueMethodName))
                    {
                        object     classObj           = CreateClass(setting.DeclaringType);
                        MethodInfo defaultValueMethod = setting.DeclaringType.GetMethod(attr.defaultValueMethodName);
                        if (defaultValueMethod.GetGenericArguments().Length == 0)
                        {
                            defaultValue = defaultValueMethod.Invoke(classObj, new object[0]).ToString();
                        }

                        DisposeTemp();
                    }

                    UserPreferences.Add(attr.Name.ToLower(), defaultValue);
                }
                catch { }
            }
        }