diff --git a/FreeSql/Extensions/TypeExtensions.cs b/FreeSql/Extensions/TypeExtensions.cs new file mode 100644 index 00000000..a5b75fd8 --- /dev/null +++ b/FreeSql/Extensions/TypeExtensions.cs @@ -0,0 +1,40 @@ +using FreeSql.Internal; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace DynamicBuilder +{ +#if net40 || NETSTANDARD2_0 +#else + public static class TypeExtensions + { + /// + /// 根据动态构建的Class Type生成实例并进行属性赋值 + /// + /// + /// + /// + public static object CreateDynamicEntityInstance(this Type type, IFreeSql fsql, + Dictionary porpertys) + { + return DynamicCompileBuilder.CreateObjectByTypeByCodeFirst(fsql, type, porpertys); + } + + /// + /// 设置对象属性值 + /// + /// + /// + public static void SetPropertyValue(this Type type, IFreeSql fsql, ref object obj, string propertyName, + object propertyValue) + { + var table = fsql.CodeFirst.GetTableByEntity(obj.GetType()); + table.ColumnsByCs[propertyName].SetValue(obj, propertyValue); + } + } +#endif +}