From 39feb6464631a51b3e477bb4fa67309b1636082b Mon Sep 17 00:00:00 2001 From: d4ilys <963922242@qq.com> Date: Tue, 25 Apr 2023 10:26:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Type=E6=89=A9=E5=B1=95?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FreeSql/Extensions/TypeExtensions.cs | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 FreeSql/Extensions/TypeExtensions.cs 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 +}