You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.6 KiB

  1. using Apewer.Internals;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace Apewer.Source
  6. {
  7. /// <summary>数据库中的表。</summary>
  8. [Serializable]
  9. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = true)]
  10. public sealed class TableAttribute : Attribute
  11. {
  12. private string _name;
  13. private bool _independent = false;
  14. private bool _locked = false;
  15. /// <summary></summary>
  16. public TableAttribute(string name = null)
  17. {
  18. _name = TableStructure.RestrictName(name, string.IsNullOrEmpty(name));
  19. }
  20. /// <summary></summary>
  21. internal TableAttribute(string name, bool underline)
  22. {
  23. _name = TableStructure.RestrictName(name, underline);
  24. }
  25. /// <summary>表名。</summary>
  26. public string Name
  27. {
  28. get { return _name; }
  29. set
  30. {
  31. if (_locked) return;
  32. _name = TableStructure.RestrictName(value, false);
  33. }
  34. }
  35. /// <summary></summary>
  36. public bool Independent
  37. {
  38. get { return _independent; }
  39. internal set
  40. {
  41. if (_locked) return;
  42. _independent = value;
  43. }
  44. }
  45. /// <summary></summary>
  46. public override int GetHashCode()
  47. {
  48. return _name.GetHashCode();
  49. }
  50. /// <summary>锁定属性,阻止修改。</summary>
  51. public void Lock()
  52. {
  53. _locked = true;
  54. }
  55. }
  56. }