public static ExternalPerSaveSettings?CreateFromXmlStream(Stream xmlStream, Func <IPropertyDefinitionBase, IRef> assignRefDelegate, PropertyChangedEventHandler?propertyChanged = null)
        {
            using var reader = XmlReader.Create(xmlStream, new XmlReaderSettings { IgnoreComments = true, IgnoreWhitespace = true });
            var serializer = new XmlSerializer(typeof(SettingsXmlModel));

            if (!serializer.CanDeserialize(reader) || serializer.Deserialize(reader) is not SettingsXmlModel settingsXmlModel)
            {
                return(null);
            }

            var subGroupDelimiter = settingsXmlModel.SubGroupDelimiter[0];

            var props = settingsXmlModel.Groups
                        .SelectMany(g => g.Properties.Select(p =>
                                                             new SettingsPropertyDefinition(SettingsUtils.GetPropertyDefinitionWrappers(p), g, assignRefDelegate(p), subGroupDelimiter)))
                        .Concat(settingsXmlModel.Properties.Select(p =>
                                                                   new SettingsPropertyDefinition(SettingsUtils.GetPropertyDefinitionWrappers(p), SettingsPropertyGroupDefinition.DefaultGroup, assignRefDelegate(p), subGroupDelimiter)));
            var propGroups = SettingsUtils.GetSettingsPropertyGroups(subGroupDelimiter, props);

            return(new ExternalPerSaveSettings(
                       settingsXmlModel.Id,
                       settingsXmlModel.DisplayName,
                       settingsXmlModel.FolderName,
                       settingsXmlModel.SubFolder,
                       settingsXmlModel.UIVersion,
                       subGroupDelimiter,
                       propertyChanged,
                       propGroups,
                       new Dictionary <string, ISettingsPresetBuilder>()));
        }
        public static IEnumerable <SettingsPropertyGroupDefinition> GetUnsortedSettingPropertyGroups(this BaseSettings settings)
        {
            if (settings is IFluentSettings fluentSettings)
            {
                return(fluentSettings.SettingPropertyGroups);
            }

            var discoverers = GenericServiceProvider.GetService <IEnumerable <ISettingsPropertyDiscoverer> >() ?? Enumerable.Empty <ISettingsPropertyDiscoverer>();
            var discoverer  = discoverers.FirstOrDefault(x => x.DiscoveryTypes.Any(y => y == settings.DiscoveryType));

            return(SettingsUtils.GetSettingsPropertyGroups(settings.SubGroupDelimiter, discoverer?.GetProperties(settings) ?? Enumerable.Empty <ISettingsPropertyDefinition>()));
        }
Exemplo n.º 3
0
 private IEnumerable <SettingsPropertyGroupDefinition> GetSettingPropertyGroups() =>
 SettingsUtils.GetSettingsPropertyGroups(SubGroupDelimiter, GetSettingProperties());
Exemplo n.º 4
0
 protected virtual IEnumerable <SettingsPropertyGroupDefinition> GetUnsortedSettingPropertyGroups() =>
 SettingsUtils.GetSettingsPropertyGroups(SubGroupDelimiter, Discoverer?.GetProperties(this) ?? Array.Empty <ISettingsPropertyDefinition>());
 public SettingsDefinition(string id, string displayName, IEnumerable <SettingsPropertyDefinition> settingsProperties)
 {
     SettingsId            = id;
     DisplayName           = displayName;
     SettingPropertyGroups = SettingsUtils.GetSettingsPropertyGroups('/', settingsProperties);
 }