Ejemplo n.º 1
0
        public ISettingsProviderClass GetSettingsFromProvider(Type settingsProviderType, ISolutionProjectModel solutionProject = null)
        {
            var res = ReflectionHelper.CreateInstance(settingsProviderType) as ISettingsProviderClass;

            foreach (PropertyInfo propertyInfo in res.GetSettableProperties())
            {
                var         settingsPropertyAttribute = CoreExtensions.GetAttributes <SettingsPropertyAttribute>(propertyInfo, false).First();
                SettingsKey settingsKey = SettingsExtensions.GetSettingsKey(propertyInfo, res);

                object defaultValue = null;
                DefaultValueAttribute defaultValueAttribute = CoreExtensions.GetAttributes <DefaultValueAttribute>(propertyInfo, false).FirstOrDefault();
                if (defaultValueAttribute != null)
                {
                    defaultValue = defaultValueAttribute.Value;
                }

                var loadedValue = Get(settingsKey, propertyInfo.PropertyType, defaultValue ?? propertyInfo.GetValue(res));
                if (solutionProject != null && settingsPropertyAttribute.Availability == SettingsAvailability.ProjectSpecific || settingsPropertyAttribute.Availability == SettingsAvailability.GlobalWithProjectSpecificOverride)
                {
                    settingsKey = SettingsExtensions.GetSettingsKey(propertyInfo, res, solutionProject);
                    loadedValue = Get(settingsKey, propertyInfo.PropertyType, loadedValue);
                }

                propertyInfo.SetValue(res, loadedValue);
            }
            return(res);
        }
Ejemplo n.º 2
0
        public object GenerateSettingsObjectForInspector(ISolutionProjectModel solutionProject = null, params object[] objectsToMerge)
        {
            var propertiesForInspector = new CustomClass("Properties", objectsToMerge);

            var settingsProviderClasses = CheckoutAndBuild2Package.GetExportedValues <ISettingsProviderClass>();

            foreach (ISettingsProviderClass settingsProviderClass in settingsProviderClasses)
            {
                var res = GetSettingsFromProvider(settingsProviderClass.GetType(), solutionProject);
                IEnumerable <PropertyInfo> settableProperties;
                if (solutionProject != null)
                {
                    settableProperties = res.GetSettableProperties(SettingsAvailability.ProjectSpecific, SettingsAvailability.GlobalWithProjectSpecificOverride);
                }
                else
                {
                    settableProperties = res.GetSettableProperties(SettingsAvailability.Global, SettingsAvailability.GlobalWithProjectSpecificOverride);
                }

                foreach (var propertyInfo in settableProperties)
                {
                    SettingsKey settingsKey = SettingsExtensions.GetSettingsKey(propertyInfo, res, solutionProject);
                    var         value       = Get(settingsKey, propertyInfo.PropertyType, propertyInfo.GetValue(res));
                    propertiesForInspector.AddProperty(propertyInfo, value, o => Set(o.GetType(), settingsKey, o));
                }
            }

            return(propertiesForInspector);
        }