mirror of
				https://github.com/nsnail/ns-ext.git
				synced 2025-10-31 23:15:28 +08:00 
			
		
		
		
	..
This commit is contained in:
		| @@ -2,7 +2,7 @@ | ||||
| // @file: ByteExtensions.cs | ||||
| // @author: tao ke | ||||
| // @mailto: taokeu@gmail.com | ||||
| // @created: 07/15/2022 20:36 | ||||
| // @created: 07/26/2022 21:57 | ||||
|  | ||||
| using System.Text; | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // @file: DateTimeExtensions.cs | ||||
| // @author: tao ke | ||||
| // @mailto: taokeu@gmail.com | ||||
| // @created: 07/15/2022 20:36 | ||||
| // @created: 07/26/2022 21:57 | ||||
|  | ||||
| // 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 | ||||
| // @author: tao ke | ||||
| // @mailto: taokeu@gmail.com | ||||
| // @created: 07/15/2022 20:36 | ||||
| // @created: 07/26/2022 21:57 | ||||
|  | ||||
| namespace NSExt; | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // @file: EnumExtensions.cs | ||||
| // @author: tao ke | ||||
| // @mailto: taokeu@gmail.com | ||||
| // @created: 07/15/2022 20:36 | ||||
| // @created: 07/26/2022 21:57 | ||||
|  | ||||
| using System.ComponentModel; | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // @file: EnumerableExtensions.cs | ||||
| // @author: tao ke | ||||
| // @mailto: taokeu@gmail.com | ||||
| // @created: 07/15/2022 20:36 | ||||
| // @created: 07/26/2022 21:57 | ||||
|  | ||||
| namespace NSExt; | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // @file: GenericExtensions.cs | ||||
| // @author: tao ke | ||||
| // @mailto: taokeu@gmail.com | ||||
| // @created: 07/15/2022 20:36 | ||||
| // @created: 07/26/2022 21:57 | ||||
|  | ||||
| namespace NSExt; | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // @file: IntExtensions.cs | ||||
| // @author: tao ke | ||||
| // @mailto: taokeu@gmail.com | ||||
| // @created: 07/15/2022 20:36 | ||||
| // @created: 07/26/2022 21:57 | ||||
|  | ||||
| namespace NSExt; | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // @file: LoggerExtensions.cs | ||||
| // @author: tao ke | ||||
| // @mailto: taokeu@gmail.com | ||||
| // @created: 07/15/2022 20:36 | ||||
| // @created: 07/26/2022 21:57 | ||||
|  | ||||
| using System.Runtime.CompilerServices; | ||||
| using Microsoft.Extensions.Logging; | ||||
| @@ -19,7 +19,7 @@ public static class LoggerExtensions | ||||
|                                             int    callerLineNumber) | ||||
|     { | ||||
|         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, | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // @file: LongExtensions.cs | ||||
| // @author: tao ke | ||||
| // @mailto: taokeu@gmail.com | ||||
| // @created: 07/15/2022 20:36 | ||||
| // @created: 07/26/2022 21:57 | ||||
|  | ||||
| namespace NSExt; | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // @file: ObjectExtensions.cs | ||||
| // @author: tao ke | ||||
| // @mailto: taokeu@gmail.com | ||||
| // @created: 07/15/2022 20:36 | ||||
| // @created: 07/26/2022 21:57 | ||||
|  | ||||
| using Newtonsoft.Json; | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // @file: StringExtensions.cs | ||||
| // @author: tao ke | ||||
| // @mailto: taokeu@gmail.com | ||||
| // @created: 07/15/2022 20:36 | ||||
| // @created: 07/26/2022 21:57 | ||||
|  | ||||
| using System.Globalization; | ||||
| using System.Text; | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // @file: UriExtensions.cs | ||||
| // @author: tao ke | ||||
| // @mailto: taokeu@gmail.com | ||||
| // @created: 07/15/2022 20:36 | ||||
| // @created: 07/26/2022 21:57 | ||||
|  | ||||
| namespace NSExt; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user