Helper.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection.Emit;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace SqlSugar
  9. {
  10. public partial class DynamicBuilder
  11. {
  12. internal CustomAttributeBuilder GetSplitEntityAttr(SplitTableAttribute sugarTable)
  13. {
  14. Type attributeType = typeof(SplitTableAttribute);
  15. ConstructorInfo attributeCtor = attributeType.GetConstructor(new Type[] { typeof(SplitType) });
  16. CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(attributeCtor, new object[] { sugarTable.SplitType },
  17. new PropertyInfo[] {
  18. attributeType.GetProperty(nameof(SplitTableAttribute.SplitType)),
  19. }
  20. , new object[] {
  21. sugarTable.SplitType
  22. });
  23. return attributeBuilder;
  24. }
  25. internal CustomAttributeBuilder GetSplitFieldAttr(SplitFieldAttribute fieldAttribute)
  26. {
  27. Type attributeType = typeof(SplitFieldAttribute);
  28. ConstructorInfo attributeCtor = attributeType.GetConstructor(new Type[] { });
  29. CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(attributeCtor, new object[] { });
  30. return attributeBuilder;
  31. }
  32. internal CustomAttributeBuilder GetEntity(SugarTable sugarTable)
  33. {
  34. Type attributeType = typeof(SugarTable);
  35. ConstructorInfo attributeCtor = attributeType.GetConstructor(new Type[] { typeof(string) });
  36. CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(attributeCtor, new object[] { "" },
  37. new PropertyInfo[] {
  38. attributeType.GetProperty(nameof(SugarTable.TableName)),
  39. attributeType.GetProperty(nameof(SugarTable.TableDescription)) ,
  40. attributeType.GetProperty(nameof(SugarTable.IsDisabledUpdateAll)) ,
  41. attributeType.GetProperty(nameof(SugarTable.IsDisabledDelete)),
  42. attributeType.GetProperty(nameof(SugarTable.IsCreateTableFiledSort)),
  43. attributeType.GetProperty(nameof(SugarTable.Discrimator))
  44. }
  45. , new object[] {
  46. sugarTable.TableName,
  47. sugarTable.TableDescription ,
  48. sugarTable.IsDisabledUpdateAll,
  49. sugarTable.IsDisabledDelete,
  50. sugarTable.IsCreateTableFiledSort,
  51. sugarTable.Discrimator
  52. });
  53. return attributeBuilder;
  54. }
  55. internal CustomAttributeBuilder GetProperty(SugarColumn sugarTable)
  56. {
  57. Type attributeType = typeof(SugarColumn);
  58. ConstructorInfo attributeCtor = attributeType.GetConstructor(new Type[] { });
  59. CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(attributeCtor, new object[] { },
  60. new PropertyInfo[] {
  61. attributeType.GetProperty(nameof(SugarColumn.IsPrimaryKey)),
  62. attributeType.GetProperty(nameof(SugarColumn.IsIdentity)),
  63. attributeType.GetProperty(nameof(SugarColumn.DefaultValue)),
  64. attributeType.GetProperty(nameof(SugarColumn.Length)),
  65. attributeType.GetProperty(nameof(SugarColumn.DecimalDigits)),
  66. attributeType.GetProperty(nameof(SugarColumn.ColumnDataType)),
  67. attributeType.GetProperty(nameof(SugarColumn.IsNullable)),
  68. attributeType.GetProperty(nameof(SugarColumn.ColumnDescription)),
  69. attributeType.GetProperty(nameof(SugarColumn.OracleSequenceName)),
  70. attributeType.GetProperty(nameof(SugarColumn.IsIgnore)),
  71. attributeType.GetProperty(nameof(SugarColumn.IsJson)),
  72. attributeType.GetProperty(nameof(SugarColumn.IsOnlyIgnoreInsert)),
  73. attributeType.GetProperty(nameof(SugarColumn.IsOnlyIgnoreUpdate)),
  74. attributeType.GetProperty(nameof(SugarColumn.OldColumnName)),
  75. attributeType.GetProperty(nameof(SugarColumn.SqlParameterDbType)),
  76. attributeType.GetProperty(nameof(SugarColumn.SqlParameterSize)),
  77. attributeType.GetProperty(nameof(SugarColumn.IsArray)),
  78. attributeType.GetProperty(nameof(SugarColumn.ColumnName))
  79. }
  80. , new object[] {
  81. sugarTable.IsPrimaryKey,
  82. sugarTable.IsIdentity,
  83. sugarTable.DefaultValue,
  84. sugarTable.Length,
  85. sugarTable.DecimalDigits,
  86. sugarTable.ColumnDataType,
  87. sugarTable.IsNullable,
  88. sugarTable.ColumnDescription,
  89. sugarTable.OracleSequenceName,
  90. sugarTable.IsIgnore,
  91. sugarTable.IsJson,
  92. sugarTable.IsOnlyIgnoreInsert,
  93. sugarTable.IsOnlyIgnoreUpdate,
  94. sugarTable.OldColumnName,
  95. sugarTable.SqlParameterDbType,
  96. sugarTable.SqlParameterSize,
  97. sugarTable.IsArray,
  98. sugarTable.ColumnName
  99. });
  100. return attributeBuilder;
  101. }
  102. }
  103. }