Browse Source

Synchronization code

pull/32/head
sunkaixuan 2 years ago
parent
commit
73c8e025a0
  1. 15
      Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/DynamicProperyBuilder.cs
  2. 20
      Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Helper.cs
  3. 10
      Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Master.cs
  4. 2
      Src/Asp.NetCore2/SqlSugar/Entities/PropertyMetadata.cs

15
Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/DynamicProperyBuilder.cs

@ -18,13 +18,24 @@ namespace SqlSugar
return new DynamicProperyBuilder();
}
public DynamicBuilder baseBuilder;
public DynamicProperyBuilder CreateProperty(string propertyName, Type properyType, SugarColumn table)
public DynamicProperyBuilder CreateProperty(string propertyName, Type properyType, SugarColumn column=null,bool isSplitField=false)
{
if (column == null)
{
column = new SugarColumn()
{
ColumnName=propertyName
};
}
PropertyMetadata addItem = new PropertyMetadata();
addItem.Name = propertyName;
addItem.Type = properyType;
addItem.CustomAttributes = new List<CustomAttributeBuilder>() { baseBuilder.GetProperty(table) };
addItem.CustomAttributes = new List<CustomAttributeBuilder>() { baseBuilder.GetProperty(column) };
baseBuilder.propertyAttr.Add(addItem);
if (isSplitField)
{
addItem.CustomAttributes.Add(baseBuilder.GetSplitFieldAttr(new SplitFieldAttribute()));
}
return this;
}
public DynamicProperyBuilder WithCache(bool isCache=true)

20
Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Helper.cs

@ -10,6 +10,26 @@ namespace SqlSugar
{
public partial class DynamicBuilder
{
internal CustomAttributeBuilder GetSplitEntityAttr(SplitTableAttribute sugarTable)
{
Type attributeType = typeof(SplitTableAttribute);
ConstructorInfo attributeCtor = attributeType.GetConstructor(new Type[] { typeof(SplitType) });
CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(attributeCtor, new object[] { sugarTable.SplitType },
new PropertyInfo[] {
attributeType.GetProperty(nameof(SplitTableAttribute.SplitType)),
}
, new object[] {
sugarTable.SplitType
});
return attributeBuilder;
}
internal CustomAttributeBuilder GetSplitFieldAttr(SplitFieldAttribute fieldAttribute)
{
Type attributeType = typeof(SplitFieldAttribute);
ConstructorInfo attributeCtor = attributeType.GetConstructor(new Type[] { });
CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(attributeCtor, new object[] { });
return attributeBuilder;
}
internal CustomAttributeBuilder GetEntity(SugarTable sugarTable)
{
Type attributeType = typeof(SugarTable);

10
Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Master.cs

@ -23,12 +23,20 @@ namespace SqlSugar
this.context = context;
}
public DynamicProperyBuilder CreateClass(string entityName, SugarTable table, Type baseType = null, Type[] interfaces = null)
public DynamicProperyBuilder CreateClass(string entityName, SugarTable table=null, Type baseType = null, Type[] interfaces = null,SplitTableAttribute splitTableAttribute=null)
{
this.baseType = baseType;
this.interfaces = interfaces;
this.entityName = entityName;
if (table == null)
{
table = new SugarTable() { TableName = entityName };
}
this.entityAttr = new List<CustomAttributeBuilder>() { GetEntity(table) };
if (splitTableAttribute != null)
{
this.entityAttr.Add(GetSplitEntityAttr(splitTableAttribute));
}
return new DynamicProperyBuilder() { baseBuilder=this};
}

2
Src/Asp.NetCore2/SqlSugar/Entities/PropertyMetadata.cs

@ -11,6 +11,6 @@ namespace SqlSugar
{
public string Name { get; set; }
public Type Type { get; set; }
public IEnumerable<CustomAttributeBuilder> CustomAttributes { get; set; }
public List<CustomAttributeBuilder> CustomAttributes { get; set; }
}
}

Loading…
Cancel
Save