public void Export <T>(T settingsObject) where T : class
        {
            ICustomExport exporter = settingsObject as ICustomExport;

            if (exporter != null)
            {
                CustomExport(exporter);
            }
            else
            {
                var type  = typeof(T);
                var props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                foreach (var prop in props)
                {
                    var value = prop.GetValue(settingsObject);
                    if (value == null)
                    {
                        this.settings[prop.Name] = null;
                    }
                    else
                    {
                        this.settings[prop.Name] = this.converter.ToString(value);
                    }
                }
            }
        }
        private void CustomExport(ICustomExport exporter)
        {
            var props = exporter.Export();

            foreach (var key in props.Keys)
            {
                var value = props[key];
                if (value == null)
                {
                    this.settings[key] = null;
                }
                else
                {
                    this.settings[key] = this.converter.ToString(value);
                }
            }
        }
Beispiel #3
0
 public CustomImportConstructor(ICustomExport customExport,
                                CustomExportWithoutInterface customExportWithoutInterface)
 {
     CustomExport = customExport ?? throw new ArgumentNullException(nameof(customExport));
     CustomExportWithoutInterface = customExportWithoutInterface ?? throw new ArgumentNullException(nameof(customExportWithoutInterface));
 }