mirror of
				https://github.com/nsnail/ns-ext.git
				synced 2025-11-01 06:15:28 +08:00 
			
		
		
		
	..
This commit is contained in:
		| @@ -2,7 +2,7 @@ | |||||||
| // @file: ByteExtensions.cs | // @file: ByteExtensions.cs | ||||||
| // @author: tao ke | // @author: tao ke | ||||||
| // @mailto: taokeu@gmail.com | // @mailto: taokeu@gmail.com | ||||||
| // @created: 07/15/2022 20:36 | // @created: 07/26/2022 21:57 | ||||||
|  |  | ||||||
| using System.Text; | using System.Text; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| // @file: DateTimeExtensions.cs | // @file: DateTimeExtensions.cs | ||||||
| // @author: tao ke | // @author: tao ke | ||||||
| // @mailto: taokeu@gmail.com | // @mailto: taokeu@gmail.com | ||||||
| // @created: 07/15/2022 20:36 | // @created: 07/26/2022 21:57 | ||||||
|  |  | ||||||
| // ReSharper disable UnusedMember.Global | // ReSharper disable UnusedMember.Global | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										38
									
								
								src/NSExt/DbCommandExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/NSExt/DbCommandExtensions.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | |||||||
|  | // @program: NSExt | ||||||
|  | // @file: DbCommandExtensions.cs | ||||||
|  | // @author: tao ke | ||||||
|  | // @mailto: taokeu@gmail.com | ||||||
|  | // @created: 08/06/2022 19:48 | ||||||
|  |  | ||||||
|  | using System.Data; | ||||||
|  | using System.Data.Common; | ||||||
|  |  | ||||||
|  | namespace NSExt; | ||||||
|  |  | ||||||
|  | public static class DbCommandExtensions | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     ///     格式化参数拼接成完整的SQL语句 | ||||||
|  |     /// </summary> | ||||||
|  |     /// <returns></returns> | ||||||
|  |     public static string ParameterFormat(this DbCommand me) | ||||||
|  |     { | ||||||
|  |         //var aa = pars.ToDictionary(it => it.ParameterName, it => it.Value); | ||||||
|  |         var sql = me.CommandText; | ||||||
|  |  | ||||||
|  |         //应逆向替换,否则由于 多个表的过滤器问题导致替换不完整  如 @TenantId1  @TenantId10 | ||||||
|  |         for (var i = me.Parameters.Count - 1; i >= 0; i--) | ||||||
|  |             sql = me.Parameters[i].DbType switch { | ||||||
|  |                       DbType.String or DbType.DateTime or DbType.Date or DbType.Time or DbType.DateTime2 | ||||||
|  |                           or DbType.DateTimeOffset or DbType.Guid or DbType.VarNumeric or DbType.AnsiStringFixedLength | ||||||
|  |                           or DbType.AnsiString | ||||||
|  |                           or DbType.StringFixedLength => sql.Replace(me.Parameters[i].ParameterName, | ||||||
|  |                                                                      "'" + me.Parameters[i].Value + "'"), | ||||||
|  |                       DbType.Boolean => sql.Replace(me.Parameters[i].ParameterName, | ||||||
|  |                                                     Convert.ToBoolean(me.Parameters[i].Value) ? "1" : "0"), | ||||||
|  |                       _ => sql.Replace(me.Parameters[i].ParameterName, me.Parameters[i].Value?.ToString()) | ||||||
|  |                   }; | ||||||
|  |  | ||||||
|  |         return sql; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -2,7 +2,7 @@ | |||||||
| // @file: DecimalExtensions.cs | // @file: DecimalExtensions.cs | ||||||
| // @author: tao ke | // @author: tao ke | ||||||
| // @mailto: taokeu@gmail.com | // @mailto: taokeu@gmail.com | ||||||
| // @created: 07/15/2022 20:36 | // @created: 07/26/2022 21:57 | ||||||
|  |  | ||||||
| namespace NSExt; | namespace NSExt; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| // @file: EnumExtensions.cs | // @file: EnumExtensions.cs | ||||||
| // @author: tao ke | // @author: tao ke | ||||||
| // @mailto: taokeu@gmail.com | // @mailto: taokeu@gmail.com | ||||||
| // @created: 07/15/2022 20:36 | // @created: 07/26/2022 21:57 | ||||||
|  |  | ||||||
| using System.ComponentModel; | using System.ComponentModel; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| // @file: EnumerableExtensions.cs | // @file: EnumerableExtensions.cs | ||||||
| // @author: tao ke | // @author: tao ke | ||||||
| // @mailto: taokeu@gmail.com | // @mailto: taokeu@gmail.com | ||||||
| // @created: 07/15/2022 20:36 | // @created: 07/26/2022 21:57 | ||||||
|  |  | ||||||
| namespace NSExt; | namespace NSExt; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| // @file: GenericExtensions.cs | // @file: GenericExtensions.cs | ||||||
| // @author: tao ke | // @author: tao ke | ||||||
| // @mailto: taokeu@gmail.com | // @mailto: taokeu@gmail.com | ||||||
| // @created: 07/15/2022 20:36 | // @created: 07/26/2022 21:57 | ||||||
|  |  | ||||||
| namespace NSExt; | namespace NSExt; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| // @file: IntExtensions.cs | // @file: IntExtensions.cs | ||||||
| // @author: tao ke | // @author: tao ke | ||||||
| // @mailto: taokeu@gmail.com | // @mailto: taokeu@gmail.com | ||||||
| // @created: 07/15/2022 20:36 | // @created: 07/26/2022 21:57 | ||||||
|  |  | ||||||
| namespace NSExt; | namespace NSExt; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| // @file: LoggerExtensions.cs | // @file: LoggerExtensions.cs | ||||||
| // @author: tao ke | // @author: tao ke | ||||||
| // @mailto: taokeu@gmail.com | // @mailto: taokeu@gmail.com | ||||||
| // @created: 07/15/2022 20:36 | // @created: 07/26/2022 21:57 | ||||||
|  |  | ||||||
| using System.Runtime.CompilerServices; | using System.Runtime.CompilerServices; | ||||||
| using Microsoft.Extensions.Logging; | using Microsoft.Extensions.Logging; | ||||||
| @@ -19,7 +19,7 @@ public static class LoggerExtensions | |||||||
|                                             int    callerLineNumber) |                                             int    callerLineNumber) | ||||||
|     { |     { | ||||||
|         return |         return | ||||||
|             $"[{Thread.CurrentThread.ManagedThreadId}#{callerName}@{Path.GetFileName(callerFilePath)}:{callerLineNumber}] {message}"; |             $"{message} <s:{Thread.CurrentThread.ManagedThreadId}#{callerName}@{Path.GetFileName(callerFilePath)}:{callerLineNumber}>"; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void Debug(this ILogger              me, |     public static void Debug(this ILogger              me, | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| // @file: LongExtensions.cs | // @file: LongExtensions.cs | ||||||
| // @author: tao ke | // @author: tao ke | ||||||
| // @mailto: taokeu@gmail.com | // @mailto: taokeu@gmail.com | ||||||
| // @created: 07/15/2022 20:36 | // @created: 07/26/2022 21:57 | ||||||
|  |  | ||||||
| namespace NSExt; | namespace NSExt; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| // @file: ObjectExtensions.cs | // @file: ObjectExtensions.cs | ||||||
| // @author: tao ke | // @author: tao ke | ||||||
| // @mailto: taokeu@gmail.com | // @mailto: taokeu@gmail.com | ||||||
| // @created: 07/15/2022 20:36 | // @created: 07/26/2022 21:57 | ||||||
|  |  | ||||||
| using Newtonsoft.Json; | using Newtonsoft.Json; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| // @file: StringExtensions.cs | // @file: StringExtensions.cs | ||||||
| // @author: tao ke | // @author: tao ke | ||||||
| // @mailto: taokeu@gmail.com | // @mailto: taokeu@gmail.com | ||||||
| // @created: 07/15/2022 20:36 | // @created: 07/26/2022 21:57 | ||||||
|  |  | ||||||
| using System.Globalization; | using System.Globalization; | ||||||
| using System.Text; | using System.Text; | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| // @file: UriExtensions.cs | // @file: UriExtensions.cs | ||||||
| // @author: tao ke | // @author: tao ke | ||||||
| // @mailto: taokeu@gmail.com | // @mailto: taokeu@gmail.com | ||||||
| // @created: 07/15/2022 20:36 | // @created: 07/26/2022 21:57 | ||||||
|  |  | ||||||
| namespace NSExt; | namespace NSExt; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user