SettingsImporter.cs 1006 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace InABox.Core
  5. {
  6. public interface ISettingsImporter
  7. {
  8. Type SettingsType { get; }
  9. void SetSettings(object settings);
  10. }
  11. public interface ISettingsImporter<TSettings> : ISettingsImporter
  12. where TSettings : BaseObject, new()
  13. {
  14. }
  15. public abstract class SettingsImporter<T, TSettings> : BaseImporter<T>, ISettingsImporter<TSettings>
  16. where T : Entity, IRemotable, IPersistent, new()
  17. where TSettings : BaseObject, new()
  18. {
  19. public TSettings Settings { get; set; } = new TSettings();
  20. public Type SettingsType => typeof(TSettings);
  21. public void SetSettings(object settings)
  22. {
  23. if(settings is TSettings tSettings)
  24. {
  25. Settings = tSettings;
  26. }
  27. else
  28. {
  29. throw new Exception($"{settings} is not a {typeof(TSettings)}");
  30. }
  31. }
  32. }
  33. }