Model.cs 952 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Linq.Expressions;
  3. using System.Windows.Media;
  4. using InABox.Configuration;
  5. using InABox.Core;
  6. using RoslynPad.Editor;
  7. namespace PRSDesktop
  8. {
  9. public interface IModel
  10. {
  11. Guid ID { get; }
  12. }
  13. public abstract class Model<TModel, TEntity> : IModel where TModel: Model<TModel, TEntity> where TEntity : Entity
  14. {
  15. public Guid ID { get; }
  16. public abstract Columns<TEntity> GetColumns();
  17. public static Columns<TEntity> Columns => (Activator.CreateInstance(typeof(TModel), new object[] { null }) as Model<TModel,TEntity>).GetColumns();
  18. public CoreRow? Row { get; }
  19. protected TType? Get<TType>(Expression<Func<TEntity,TType>> property) => Row != null ? Row.Get<TEntity,TType>(property) : default(TType);
  20. public Model(CoreRow row)
  21. {
  22. Row = row;
  23. ID = Get(x => x.ID);
  24. }
  25. }
  26. }