Skip to content

Commit 39feb64

Browse files
committed
增加Type扩展方法
1 parent 958b6c2 commit 39feb64

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using FreeSql.Internal;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace DynamicBuilder
10+
{
11+
#if net40 || NETSTANDARD2_0
12+
#else
13+
public static class TypeExtensions
14+
{
15+
/// <summary>
16+
/// 根据动态构建的Class Type生成实例并进行属性赋值
17+
/// </summary>
18+
/// <param name="type"></param>
19+
/// <param name="porpertys"></param>
20+
/// <returns></returns>
21+
public static object CreateDynamicEntityInstance(this Type type, IFreeSql fsql,
22+
Dictionary<string, object> porpertys)
23+
{
24+
return DynamicCompileBuilder.CreateObjectByTypeByCodeFirst(fsql, type, porpertys);
25+
}
26+
27+
/// <summary>
28+
/// 设置对象属性值
29+
/// </summary>
30+
/// <param name="fsql"></param>
31+
/// <returns></returns>
32+
public static void SetPropertyValue(this Type type, IFreeSql fsql, ref object obj, string propertyName,
33+
object propertyValue)
34+
{
35+
var table = fsql.CodeFirst.GetTableByEntity(obj.GetType());
36+
table.ColumnsByCs[propertyName].SetValue(obj, propertyValue);
37+
}
38+
}
39+
#endif
40+
}

0 commit comments

Comments
 (0)