using Quadarax.Foundation.Core.Data.Interface.Entity; using Quadarax.Foundation.Core.Object.Extensions; using Quadarax.Foundation.Core.Reflection.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().GetAllProperties(); 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().GetAllProperties(); var result = this.GetAllPropertyValues(). Select(x=> new Tuple(x.Key, properties.First(y=>y.Name == x.Key).GetFinalPropertyType().FullName ?? string.Empty, properties.First(y=>y.Name == x.Key).GetValue(this))).ToArray(); return result; } public virtual void SetDefaults() { } } }