mirror of
				https://github.com/nsnail/ns-ext.git
				synced 2025-10-31 23:15:28 +08:00 
			
		
		
		
	..
This commit is contained in:
		| @@ -1,4 +1,4 @@ | ||||
| namespace NSExt; | ||||
| namespace NSExt.Extensions; | ||||
| 
 | ||||
| public static class ByteExtensions | ||||
| { | ||||
| @@ -1,6 +1,6 @@ | ||||
| // ReSharper disable UnusedMember.Global | ||||
| 
 | ||||
| namespace NSExt; | ||||
| namespace NSExt.Extensions; | ||||
| 
 | ||||
| public static class DateTimeExtensions | ||||
| { | ||||
| @@ -1,4 +1,4 @@ | ||||
| namespace NSExt; | ||||
| namespace NSExt.Extensions; | ||||
| 
 | ||||
| public static class DbCommandExtensions | ||||
| { | ||||
| @@ -1,4 +1,4 @@ | ||||
| namespace NSExt; | ||||
| namespace NSExt.Extensions; | ||||
| 
 | ||||
| public static class DecimalExtensions | ||||
| { | ||||
| @@ -1,4 +1,4 @@ | ||||
| namespace NSExt; | ||||
| namespace NSExt.Extensions; | ||||
| 
 | ||||
| public static class EnumExtensions | ||||
| { | ||||
| @@ -1,4 +1,4 @@ | ||||
| namespace NSExt; | ||||
| namespace NSExt.Extensions; | ||||
| 
 | ||||
| public static class EnumerableExtensions | ||||
| { | ||||
| @@ -1,4 +1,4 @@ | ||||
| namespace NSExt; | ||||
| namespace NSExt.Extensions; | ||||
| 
 | ||||
| public static class GenericExtensions | ||||
| { | ||||
| @@ -1,4 +1,4 @@ | ||||
| namespace NSExt; | ||||
| namespace NSExt.Extensions; | ||||
| 
 | ||||
| public static class IntExtensions | ||||
| { | ||||
| @@ -1,6 +1,6 @@ | ||||
| // ReSharper disable TemplateIsNotCompileTimeConstantProblem | ||||
| 
 | ||||
| namespace NSExt; | ||||
| namespace NSExt.Extensions; | ||||
| 
 | ||||
| public static class LoggerExtensions | ||||
| { | ||||
| @@ -1,4 +1,4 @@ | ||||
| namespace NSExt; | ||||
| namespace NSExt.Extensions; | ||||
| 
 | ||||
| public static class LongExtensions | ||||
| { | ||||
							
								
								
									
										33
									
								
								src/NSExt/Extensions/ObjectExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/NSExt/Extensions/ObjectExtensions.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| using Newtonsoft.Json.Serialization; | ||||
|  | ||||
| namespace NSExt.Extensions; | ||||
|  | ||||
| public static class ObjectExtensions | ||||
| { | ||||
|     /// <summary> | ||||
|     ///     将一个对象序列化成json文本 | ||||
|     /// </summary> | ||||
|     /// <param name="me">指定对象</param> | ||||
|     /// <param name="format">是否格式化</param> | ||||
|     /// <returns>json文本</returns> | ||||
|     public static string Json(this object me, bool format = false) | ||||
|     { | ||||
|         return JsonConvert.SerializeObject(me, format ? Formatting.Indented : Formatting.None); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /// <summary> | ||||
|     ///     将一个对象序列化成json文本(小驼峰属性名) | ||||
|     /// </summary> | ||||
|     /// <param name="me">指定对象</param> | ||||
|     /// <param name="format">是否格式化</param> | ||||
|     /// <returns>json文本</returns> | ||||
|     public static string JsonCamelCase(this object me, bool format = false) | ||||
|     { | ||||
|         return JsonConvert.SerializeObject(me, | ||||
|                                            new JsonSerializerSettings { | ||||
|                                                ContractResolver = new CamelCasePropertyNamesContractResolver(), | ||||
|                                                Formatting       = format ? Formatting.Indented : Formatting.None | ||||
|                                            }); | ||||
|     } | ||||
| } | ||||
| @@ -2,11 +2,8 @@ | ||||
| 
 | ||||
| 
 | ||||
| using System.Security.Cryptography; | ||||
| using HMACMD5 = SshNet.Security.Cryptography.HMACMD5; | ||||
| using HMACSHA1 = SshNet.Security.Cryptography.HMACSHA1; | ||||
| using MD5 = SshNet.Security.Cryptography.MD5; | ||||
| 
 | ||||
| namespace NSExt; | ||||
| namespace NSExt.Extensions; | ||||
| 
 | ||||
| public static class StringExtensions | ||||
| { | ||||
| @@ -280,7 +277,7 @@ public static class StringExtensions | ||||
|     /// <returns>hash摘要的16进制文本形式(无连字符小写)</returns> | ||||
|     public static string Sha1(this string me, Encoding e) | ||||
|     { | ||||
|         using var sha1 = HashAlgorithm.Create(); | ||||
|         using var sha1 = SHA1.Create(); | ||||
|         return BitConverter.ToString(sha1.ComputeHash(e.GetBytes(me))) | ||||
|                            .Replace("-", string.Empty) | ||||
|                            .ToLower(CultureInfo.CurrentCulture); | ||||
| @@ -311,7 +308,7 @@ public static class StringExtensions | ||||
|     /// <returns>hash摘要的16进制文本形式(无连字符小写)</returns> | ||||
|     public static string Md5(this string me, Encoding e) | ||||
|     { | ||||
|         using var md5 = new MD5(); | ||||
|         using var md5 = MD5.Create(); | ||||
|         return BitConverter.ToString(md5.ComputeHash(e.GetBytes(me))) | ||||
|                            .Replace("-", string.Empty) | ||||
|                            .ToLower(CultureInfo.CurrentCulture); | ||||
| @@ -1,4 +1,4 @@ | ||||
| namespace NSExt; | ||||
| namespace NSExt.Extensions; | ||||
| 
 | ||||
| public static class UriExtensions | ||||
| { | ||||
| @@ -9,4 +9,3 @@ global using System.Web; | ||||
| global using Newtonsoft.Json; | ||||
| global using Newtonsoft.Json.Linq; | ||||
| global using System.ComponentModel; | ||||
| global using SshNet.Security.Cryptography; | ||||
|   | ||||
| @@ -8,14 +8,13 @@ | ||||
|     </PropertyGroup> | ||||
|  | ||||
|     <ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' "> | ||||
|         <PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0"/> | ||||
|         <PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" /> | ||||
|     </ItemGroup> | ||||
|     <ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' "> | ||||
|         <PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0-preview.7.22375.6"/> | ||||
|         <PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0-preview.7.22375.6" /> | ||||
|     </ItemGroup> | ||||
|     <ItemGroup> | ||||
|         <PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta2"/> | ||||
|         <PackageReference Include="SshNet.Security.Cryptography" Version="1.3.0"/> | ||||
|         <PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta2" /> | ||||
|     </ItemGroup> | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -1,15 +0,0 @@ | ||||
| namespace NSExt; | ||||
|  | ||||
| public static class ObjectExtensions | ||||
| { | ||||
|     /// <summary> | ||||
|     ///     将一个对象序列化成json文本 | ||||
|     /// </summary> | ||||
|     /// <param name="me">指定对象</param> | ||||
|     /// <param name="format">是否格式化</param> | ||||
|     /// <returns>json文本</returns> | ||||
|     public static string Json(this object me, bool format = false) | ||||
|     { | ||||
|         return JsonConvert.SerializeObject(me, format ? Formatting.Indented : Formatting.None); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user