mirror of
https://github.com/nsnail/ns-ext.git
synced 2025-04-18 23:22:51 +08:00
feat
This commit is contained in:
parent
b6279bb0bb
commit
a61d057c76
@ -1,18 +1,18 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Authors>nsnail</Authors>
|
||||
<Product>NSExt</Product>
|
||||
<Copyright>© 2006-2022 nsnail</Copyright>
|
||||
<RepositoryUrl>https://github.com/nsnail/ns-ext.git</RepositoryUrl>
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
<EmbedUntrackedSource>true</EmbedUntrackedSource>
|
||||
<EmbedAllSources>true</EmbedAllSources>
|
||||
<RepositoryType>Git</RepositoryType>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageProjectUrl>https://github.com/nsnail/ns-ext.git</PackageProjectUrl>
|
||||
<PackageOutputPath>../../build/nupkgs</PackageOutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<Authors>nsnail</Authors>
|
||||
<Product>NSExt</Product>
|
||||
<Copyright>© 2006-2022 nsnail</Copyright>
|
||||
<RepositoryUrl>https://github.com/nsnail/ns-ext.git</RepositoryUrl>
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
<EmbedUntrackedSource>true</EmbedUntrackedSource>
|
||||
<EmbedAllSources>true</EmbedAllSources>
|
||||
<RepositoryType>Git</RepositoryType>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageProjectUrl>https://github.com/nsnail/ns-ext.git</PackageProjectUrl>
|
||||
<PackageOutputPath>../../build/nupkgs</PackageOutputPath>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@ -34,4 +34,8 @@ public static class ByteExtensions
|
||||
{
|
||||
return me.HexDe(Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -24,3 +24,9 @@ public static class CharExtensions
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -87,3 +87,8 @@ public static class DateTimeExtensions
|
||||
return me.ToString("yyyyMMdd");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -28,3 +28,9 @@ public static class DbCommandExtensions
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -16,3 +16,9 @@ public static class DecimalExtensions
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -17,3 +17,8 @@ public static class EnumExtensions
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -26,3 +26,8 @@ public static class EnumerableExtensions
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -43,3 +43,9 @@ public static class GenericExtensions
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -36,3 +36,8 @@ public static class IntExtensions
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -18,4 +18,8 @@ public static class JsonSerializerOptionsExtensions
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -66,3 +66,8 @@ public static class LoggerExtensions
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -28,3 +28,8 @@ public static class LongExtensions
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -19,3 +19,8 @@ public static class ObjectExtensions
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
26
src/NSExt/Extensions/StreamExtensions.cs
Normal file
26
src/NSExt/Extensions/StreamExtensions.cs
Normal file
@ -0,0 +1,26 @@
|
||||
namespace NSExt.Extensions;
|
||||
|
||||
public static class StreamExtensions
|
||||
{
|
||||
public static long FirstByteIndex(this Stream me, byte[] findBytes)
|
||||
{
|
||||
int data;
|
||||
while ((data = me.ReadByte()) != -1)
|
||||
if (findBytes.Contains((byte)data))
|
||||
return me.Position;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static bool IsTextStream(this Stream me)
|
||||
{
|
||||
return me.FirstByteIndex(new byte[] {
|
||||
0x00,
|
||||
0xff
|
||||
}) < 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -11,6 +11,21 @@ public static class StringExtensions
|
||||
private static readonly JsonSerializerOptions _DEFAULT_JSON_SERIALIZER_OPTIONS =
|
||||
default(JsonSerializerOptions).NewJsonSerializerOptions();
|
||||
|
||||
/// <summary>
|
||||
/// MD5 hmac编码
|
||||
/// </summary>
|
||||
/// <param name="me">字符串</param>
|
||||
/// <param name="key">密钥</param>
|
||||
/// <param name="e">字符串使用的编码</param>
|
||||
/// <returns>hash摘要的16进制文本形式(无连字符小写)</returns>
|
||||
private static string Md5Hmac(this string me, string key, Encoding e)
|
||||
{
|
||||
using var md5Hmac = new HMACMD5(e.GetBytes(key));
|
||||
return BitConverter.ToString(md5Hmac.ComputeHash(e.GetBytes(me)))
|
||||
.Replace("-", string.Empty)
|
||||
.ToLower(CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// aes加密
|
||||
/// </summary>
|
||||
@ -554,19 +569,8 @@ public static class StringExtensions
|
||||
{
|
||||
return Uri.UnescapeDataString(me);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// MD5 hmac编码
|
||||
/// </summary>
|
||||
/// <param name="me">字符串</param>
|
||||
/// <param name="key">密钥</param>
|
||||
/// <param name="e">字符串使用的编码</param>
|
||||
/// <returns>hash摘要的16进制文本形式(无连字符小写)</returns>
|
||||
private static string Md5Hmac(this string me, string key, Encoding e)
|
||||
{
|
||||
using var md5Hmac = new HMACMD5(e.GetBytes(key));
|
||||
return BitConverter.ToString(md5Hmac.ComputeHash(e.GetBytes(me)))
|
||||
.Replace("-", string.Empty)
|
||||
.ToLower(CultureInfo.CurrentCulture);
|
||||
}
|
||||
}
|
@ -16,4 +16,8 @@ public static class TypeExtensions
|
||||
.SelectMany(interfaceType => interfaceType.GetCustomAttributes(attributeType, true)))
|
||||
.Cast<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -15,3 +15,9 @@ public static class UriExtensions
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -6,4 +6,4 @@ global using System.Globalization;
|
||||
global using System.Text;
|
||||
global using System.Text.RegularExpressions;
|
||||
global using System.Web;
|
||||
global using System.ComponentModel;
|
||||
global using System.ComponentModel;
|
||||
|
@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<VersionPrefix>1.0.2</VersionPrefix>
|
||||
<VersionPrefix>1.0.3</VersionPrefix>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
x
Reference in New Issue
Block a user