選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

BaseObject.cs 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.DataAnnotations.Schema;
  5. using System.Reflection;
  6. namespace ProRestaurant.Models
  7. {
  8. public class BaseObject
  9. {
  10. #region Properties
  11. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  12. [Key]
  13. public int Id { get; set; }
  14. public DateTime Created { get; set; } = DateTime.Now;
  15. public DateTime Modified { get; set; } = DateTime.Now;
  16. public string ModifiedBy { get; set; }
  17. public bool IsDeleted { get; set; } = false;
  18. #endregion
  19. #region Methods
  20. public virtual void UpdateModified(string modifiedBy)
  21. {
  22. Modified = DateTime.Now;
  23. if (string.IsNullOrEmpty(modifiedBy))
  24. {
  25. ModifiedBy = modifiedBy;
  26. }
  27. }
  28. public object this[string propertyName]
  29. {
  30. get { return GetType().GetProperty(propertyName).GetValue(this, null); }
  31. set { GetType().GetProperty(propertyName).SetValue(this, value, null); }
  32. }
  33. public string[] GetAllProperties()
  34. {
  35. if (this == null) return new string[] { };
  36. Type t = GetType();
  37. PropertyInfo[] props = t.GetProperties();
  38. List<string> propNames = new List<string>();
  39. foreach (PropertyInfo prp in props)
  40. {
  41. propNames.Add(prp.Name);
  42. }
  43. return propNames.ToArray();
  44. }
  45. #endregion
  46. }
  47. }