Update dynamic class

This commit is contained in:
sunkaixuan 2023-04-08 12:46:33 +08:00
parent f56795bd55
commit 39a70306d9
2 changed files with 14 additions and 3 deletions

View File

@ -18,12 +18,19 @@ namespace SqlSugar
return new DynamicProperyBuilder(); return new DynamicProperyBuilder();
} }
public DynamicBuilder baseBuilder; public DynamicBuilder baseBuilder;
public DynamicProperyBuilder CreateProperty(string propertyName, Type properyType, SugarColumn table) public DynamicProperyBuilder CreateProperty(string propertyName, Type properyType, SugarColumn column=null)
{ {
if (column == null)
{
column = new SugarColumn()
{
ColumnName=propertyName
};
}
PropertyMetadata addItem = new PropertyMetadata(); PropertyMetadata addItem = new PropertyMetadata();
addItem.Name = propertyName; addItem.Name = propertyName;
addItem.Type = properyType; addItem.Type = properyType;
addItem.CustomAttributes = new List<CustomAttributeBuilder>() { baseBuilder.GetProperty(table) }; addItem.CustomAttributes = new List<CustomAttributeBuilder>() { baseBuilder.GetProperty(column) };
baseBuilder.propertyAttr.Add(addItem); baseBuilder.propertyAttr.Add(addItem);
return this; return this;
} }

View File

@ -23,11 +23,15 @@ namespace SqlSugar
this.context = context; 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)
{ {
this.baseType = baseType; this.baseType = baseType;
this.interfaces = interfaces; this.interfaces = interfaces;
this.entityName = entityName; this.entityName = entityName;
if (table == null)
{
table = new SugarTable() { TableName = entityName };
}
this.entityAttr = new List<CustomAttributeBuilder>() { GetEntity(table) }; this.entityAttr = new List<CustomAttributeBuilder>() { GetEntity(table) };
return new DynamicProperyBuilder() { baseBuilder=this}; return new DynamicProperyBuilder() { baseBuilder=this};
} }