using System.Reflection; using Quadarax.Foundation.Core.Data.Interface.Entity; using Quadarax.Foundation.Core.Object.Extensions; namespace Quadarax.Application.QLiberace.Common.Settings { public abstract class ModuleSetting : IDto { public void SetData(IEnumerable> data) { if (data == null) throw new ArgumentNullException(nameof(data)); var properties = this.GetType().GetProperties(BindingFlags.Public); foreach (var item in data) { var property = properties.FirstOrDefault(x => string.Equals(x.Name, item.Item1)); if (property == null) throw ExceptionFactory.CreateException(ExceptionLibrary.ExceptionsCodes.SettingsHasNoPropertyCode, item.Item1, this.GetType().Name); property.SetValue(this, item.Item3); } } public IEnumerable> GetData() { var properties = this.GetType().GetProperties(BindingFlags.Public); var result = this.GetAllPropertyValues(). Select(x=> new Tuple(x.Key, properties.First(y=>y.Name == x.Key).PropertyType.Name, properties.First(y=>y.Name == x.Key).GetValue(this))); return result; } } }