|
9 | 9 | namespace FreeSql.Extensions.EntityUtil { |
10 | 10 | public static class EntityUtilExtensions { |
11 | 11 |
|
12 | | - static MethodInfo MethodStringBuilderAppend = typeof(StringBuilder).GetMethod("Append", new Type[] { typeof(object) }); |
13 | | - static MethodInfo MethodStringBuilderToString = typeof(StringBuilder).GetMethod("ToString", new Type[0]); |
14 | | - static PropertyInfo MethodStringBuilderLength = typeof(StringBuilder).GetProperty("Length"); |
15 | | - static MethodInfo MethodStringConcat = typeof(string).GetMethod("Concat", new Type[] { typeof(object) }); |
16 | | - static MethodInfo MethodFreeUtilNewMongodbId = typeof(FreeUtil).GetMethod("NewMongodbId"); |
| 12 | + static readonly MethodInfo MethodStringBuilderAppend = typeof(StringBuilder).GetMethod("Append", new Type[] { typeof(object) }); |
| 13 | + static readonly MethodInfo MethodStringBuilderToString = typeof(StringBuilder).GetMethod("ToString", new Type[0]); |
| 14 | + static readonly PropertyInfo MethodStringBuilderLength = typeof(StringBuilder).GetProperty("Length"); |
| 15 | + static readonly MethodInfo MethodStringConcat = typeof(string).GetMethod("Concat", new Type[] { typeof(object) }); |
| 16 | + static readonly MethodInfo MethodFreeUtilNewMongodbId = typeof(FreeUtil).GetMethod("NewMongodbId"); |
17 | 17 |
|
18 | 18 | static ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Func<object, string>>> _dicGetEntityKeyString = new ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Func<object, string>>>(); |
19 | 19 | /// <summary> |
20 | 20 | /// 获取实体的主键值,以 "*|_,[,_|*" 分割,当任意一个主键属性无值时(当Guid无值时,会生成有序的新值),返回 null |
21 | 21 | /// </summary> |
22 | | - /// <typeparam name="TEntity"></typeparam> |
23 | | - /// <param name="_table"></param> |
| 22 | + /// <param name="orm"></param> |
| 23 | + /// <param name="entityType"></param> |
24 | 24 | /// <param name="entity"></param> |
| 25 | + /// <param name="splitString"></param> |
25 | 26 | /// <returns></returns> |
26 | 27 | //public static string GetEntityKeyString<TEntity>(this IFreeSql orm, TEntity entity, string splitString = "*|_,[,_|*") => GetEntityKeyString(orm, typeof(TEntity), entity, splitString); |
27 | 28 | public static string GetEntityKeyString(this IFreeSql orm, Type entityType, object entity, string splitString = "*|_,[,_|*") { |
@@ -126,8 +127,8 @@ public static string GetEntityKeyString(this IFreeSql orm, Type entityType, obje |
126 | 127 | /// <summary> |
127 | 128 | /// 获取实体的主键值,多个主键返回数组 |
128 | 129 | /// </summary> |
129 | | - /// <typeparam name="TEntity"></typeparam> |
130 | | - /// <param name="_table"></param> |
| 130 | + /// <param name="orm"></param> |
| 131 | + /// <param name="entityType"></param> |
131 | 132 | /// <param name="entity"></param> |
132 | 133 | /// <returns></returns> |
133 | 134 | //public static object[] GetEntityKeyValues<TEntity>(this IFreeSql orm, TEntity entity) => GetEntityKeyValues(orm, typeof(TEntity), entity); |
@@ -165,9 +166,10 @@ public static object[] GetEntityKeyValues(this IFreeSql orm, Type entityType, ob |
165 | 166 | /// <summary> |
166 | 167 | /// 获取实体的属性值 |
167 | 168 | /// </summary> |
168 | | - /// <typeparam name="TEntity"></typeparam> |
169 | | - /// <param name="_table"></param> |
| 169 | + /// <param name="orm"></param> |
| 170 | + /// <param name="entityType"></param> |
170 | 171 | /// <param name="entity"></param> |
| 172 | + /// <param name="propertyName"></param> |
171 | 173 | /// <returns></returns> |
172 | 174 | //public static object GetEntityValueWithPropertyName<TEntity>(this IFreeSql orm, TEntity entity, string propertyName) => GetEntityKeyValues(orm, typeof(TEntity), entity, propertyName); |
173 | 175 | public static object GetEntityValueWithPropertyName(this IFreeSql orm, Type entityType, object entity, string propertyName) { |
@@ -202,8 +204,8 @@ public static object GetEntityValueWithPropertyName(this IFreeSql orm, Type enti |
202 | 204 | /// <summary> |
203 | 205 | /// 获取实体的所有数据,以 (1, 2, xxx) 的形式 |
204 | 206 | /// </summary> |
205 | | - /// <typeparam name="TEntity"></typeparam> |
206 | | - /// <param name="_table"></param> |
| 207 | + /// <param name="orm"></param> |
| 208 | + /// <param name="entityType"></param> |
207 | 209 | /// <param name="entity"></param> |
208 | 210 | /// <returns></returns> |
209 | 211 | //public static string GetEntityString<TEntity>(this IFreeSql orm, TEntity entity) => GetEntityString(orm, typeof(TEntity), entity); |
@@ -321,8 +323,8 @@ public static void MapEntityKeyValue(this IFreeSql orm, Type entityType, object |
321 | 323 | /// <summary> |
322 | 324 | /// 设置实体中主键内的自增字段值(若存在) |
323 | 325 | /// </summary> |
324 | | - /// <typeparam name="TEntity"></typeparam> |
325 | 326 | /// <param name="orm"></param> |
| 327 | + /// <param name="entityType"></param> |
326 | 328 | /// <param name="entity"></param> |
327 | 329 | /// <param name="idtval"></param> |
328 | 330 | //public static void SetEntityIdentityValueWithPrimary<TEntity>(this IFreeSql orm, TEntity entity, long idtval) => SetEntityIdentityValueWithPrimary(orm, typeof(TEntity), entity, idtval); |
@@ -355,8 +357,8 @@ public static void SetEntityIdentityValueWithPrimary(this IFreeSql orm, Type ent |
355 | 357 | /// <summary> |
356 | 358 | /// 获取实体中主键内的自增字段值(若存在) |
357 | 359 | /// </summary> |
358 | | - /// <typeparam name="TEntity"></typeparam> |
359 | 360 | /// <param name="orm"></param> |
| 361 | + /// <param name="entityType"></param> |
360 | 362 | /// <param name="entity"></param> |
361 | 363 | //public static long GetEntityIdentityValueWithPrimary<TEntity>(this IFreeSql orm, TEntity entity) => GetEntityIdentityValueWithPrimary(orm, typeof(TEntity), entity); |
362 | 364 | public static long GetEntityIdentityValueWithPrimary(this IFreeSql orm, Type entityType, object entity) { |
@@ -402,8 +404,8 @@ public static long GetEntityIdentityValueWithPrimary(this IFreeSql orm, Type ent |
402 | 404 | /// <summary> |
403 | 405 | /// 清除实体的主键值,将自增、Guid类型的主键值清除 |
404 | 406 | /// </summary> |
405 | | - /// <typeparam name="TEntity"></typeparam> |
406 | 407 | /// <param name="orm"></param> |
| 408 | + /// <param name="entityType"></param> |
407 | 409 | /// <param name="entity"></param> |
408 | 410 | //public static void ClearEntityPrimaryValueWithIdentityAndGuid<TEntity>(this IFreeSql orm, TEntity entity) => ClearEntityPrimaryValueWithIdentityAndGuid(orm, typeof(TEntity), entity); |
409 | 411 | public static void ClearEntityPrimaryValueWithIdentityAndGuid(this IFreeSql orm, Type entityType, object entity) { |
@@ -446,8 +448,8 @@ public static void ClearEntityPrimaryValueWithIdentityAndGuid(this IFreeSql orm, |
446 | 448 | /// <summary> |
447 | 449 | /// 清除实体的主键值,将自增、Guid类型的主键值清除 |
448 | 450 | /// </summary> |
449 | | - /// <typeparam name="TEntity"></typeparam> |
450 | 451 | /// <param name="orm"></param> |
| 452 | + /// <param name="entityType"></param> |
451 | 453 | /// <param name="entity"></param> |
452 | 454 | //public static void ClearEntityPrimaryValueWithIdentity<TEntity>(this IFreeSql orm, TEntity entity) => ClearEntityPrimaryValueWithIdentity(orm, typeof(TEntity), entity); |
453 | 455 | public static void ClearEntityPrimaryValueWithIdentity(this IFreeSql orm, Type entityType, object entity) { |
@@ -480,10 +482,11 @@ public static void ClearEntityPrimaryValueWithIdentity(this IFreeSql orm, Type e |
480 | 482 | /// <summary> |
481 | 483 | /// 对比两个实体值,返回相同/或不相同的列名 |
482 | 484 | /// </summary> |
483 | | - /// <typeparam name="TEntity"></typeparam> |
484 | 485 | /// <param name="orm"></param> |
| 486 | + /// <param name="entityType"></param> |
485 | 487 | /// <param name="entity1"></param> |
486 | 488 | /// <param name="entity2"></param> |
| 489 | + /// <param name="isEqual"></param> |
487 | 490 | /// <returns></returns> |
488 | 491 | //public static string[] CompareEntityValueReturnColumns<TEntity>(this IFreeSql orm, TEntity entity1, TEntity entity2, bool isEqual) => CompareEntityValueReturnColumns(orm, typeof(TEntity), entity1, entity2, isEqual); |
489 | 492 | public static string[] CompareEntityValueReturnColumns(this IFreeSql orm, Type entityType, object entity1, object entity2, bool isEqual) { |
@@ -534,11 +537,11 @@ public static string[] CompareEntityValueReturnColumns(this IFreeSql orm, Type e |
534 | 537 | /// <summary> |
535 | 538 | /// 设置实体中某属性的数值增加指定的值 |
536 | 539 | /// </summary> |
537 | | - /// <typeparam name="TEntity"></typeparam> |
538 | 540 | /// <param name="orm"></param> |
| 541 | + /// <param name="entityType"></param> |
539 | 542 | /// <param name="entity"></param> |
540 | 543 | /// <param name="propertyName"></param> |
541 | | - /// <param name="value"></param> |
| 544 | + /// <param name="incrBy"></param> |
542 | 545 | //public static void SetEntityIncrByWithPropertyName<TEntity>(this IFreeSql orm, TEntity entity, string propertyName, int incrBy) => SetEntityIncrByWithPropertyName(orm, typeof(TEntity), entity, propertyName, incrBy); |
543 | 546 | public static void SetEntityIncrByWithPropertyName(this IFreeSql orm, Type entityType, object entity, string propertyName, int incrBy) { |
544 | 547 | if (entity == null) return; |
@@ -576,8 +579,8 @@ public static void SetEntityIncrByWithPropertyName(this IFreeSql orm, Type entit |
576 | 579 | /// <summary> |
577 | 580 | /// 设置实体中某属性的值 |
578 | 581 | /// </summary> |
579 | | - /// <typeparam name="TEntity"></typeparam> |
580 | 582 | /// <param name="orm"></param> |
| 583 | + /// <param name="entityType"></param> |
581 | 584 | /// <param name="entity"></param> |
582 | 585 | /// <param name="propertyName"></param> |
583 | 586 | /// <param name="value"></param> |
|
0 commit comments