| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 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<Tuple<string, string, object?>> 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<Tuple<string, string, object?>> GetData()
- {
- var properties = this.GetType().GetAllProperties();
- var result = this.GetAllPropertyValues().
- Select(x=> new Tuple<string, string, object?>(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()
- {
- }
- }
- }
|