mirror of
https://github.com/nsnail/ns-ext.git
synced 2025-05-03 04:32:50 +08:00
Compare commits
2 Commits
8c1083f732
...
943d151048
Author | SHA1 | Date | |
---|---|---|---|
![]() |
943d151048 | ||
![]() |
09352ac5ea |
@ -1,4 +1,8 @@
|
|||||||
<wpf:ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve">
|
<wpf:ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve">
|
||||||
|
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/ReSpeller/ReSpellerEnabled/@EntryValue">False</s:Boolean>
|
<s:Boolean x:Key="/Default/ReSpeller/ReSpellerEnabled/@EntryValue">False</s:Boolean>
|
||||||
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_CODE/@EntryValue">1</s:Int64>
|
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_CODE/@EntryValue">1</s:Int64>
|
||||||
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue">1</s:Int64>
|
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue">1</s:Int64>
|
||||||
|
38
README.md
38
README.md
@ -1,27 +1,27 @@
|
|||||||
# ns-ext
|
# ns-ext
|
||||||
|
|
||||||
[中](README.zh-CN.md) | **En**
|
[中](README.zh-CN.md) | **En**
|
||||||
The **ns-ext** is a .NET extension function library, containing the following types of extension modules:
|
The **ns-ext** is a .NET extension function library, containing the following types of extension modules:
|
||||||
|
|
||||||
|
| Features | File name |
|
||||||
| Features | File name |
|
|------------------------------------------|------------------------------------|
|
||||||
| -------- | ---------------------------------- |
|
| Byte type extension | ByteExtensions.cs |
|
||||||
| Byte type extension | ByteExtensions.cs |
|
| Character Type Extensions | CharExtensions.cs |
|
||||||
| Character Type Extensions | CharExtensions.cs |
|
| Date Type Extensions | DateTimeExtensions.cs |
|
||||||
| Date Type Extensions | DateTimeExtensions.cs |
|
| Database command type extension | DbCommandExtensions.cs |
|
||||||
| Database command type extension | DbCommandExtensions.cs |
|
| Decimal Number Type extension | DecimalExtensions.cs |
|
||||||
| Decimal Number Type extension | DecimalExtensions.cs |
|
| Enumable type extension | EnumerableExtensions.cs |
|
||||||
| Enumable type extension | EnumerableExtensions.cs |
|
| Enumeration type extension | EnumExtensions.cs |
|
||||||
| Enumeration type extension | EnumExtensions.cs |
|
| General type extension | GenericExtensions.cs |
|
||||||
| General type extension | GenericExtensions.cs |
|
| Integer type extension | IntExtensions.cs |
|
||||||
| Integer type extension | IntExtensions.cs |
|
|
||||||
| Json Serialization option type extension | JsonSerializerOptionsExtensions.cs |
|
| Json Serialization option type extension | JsonSerializerOptionsExtensions.cs |
|
||||||
| Log type extension | LoggerExtensions.cs |
|
| Log type extension | LoggerExtensions.cs |
|
||||||
| Long integer extension | LongExtensions.cs |
|
| Long integer extension | LongExtensions.cs |
|
||||||
| Object type extension | ObjectExtensions.cs |
|
| Object type extension | ObjectExtensions.cs |
|
||||||
| Stream type extension | StreamExtensions.cs |
|
| Stream type extension | StreamExtensions.cs |
|
||||||
| String type extension | StringExtensions.cs |
|
| String type extension | StringExtensions.cs |
|
||||||
| Prototype type extension | TypeExtensions.cs |
|
| Prototype type extension | TypeExtensions.cs |
|
||||||
| Resource locator type extension | UriExtensions.cs |
|
| Resource locator type extension | UriExtensions.cs |
|
||||||
|
|
||||||
## Quick start
|
## Quick start
|
||||||
|
|
||||||
|
@ -42,17 +42,20 @@ public static class ByteExtensions
|
|||||||
/// <param name="me">me</param>
|
/// <param name="me">me</param>
|
||||||
/// <param name="upperCase">是否大写</param>
|
/// <param name="upperCase">是否大写</param>
|
||||||
/// <param name="splitShar">字节间分隔符</param>
|
/// <param name="splitShar">字节间分隔符</param>
|
||||||
public static string String(this byte[] me, bool upperCase = true, string splitShar = null)
|
/// <param name="splitInterval">分隔符跳跃字节数</param>
|
||||||
|
public static string String(this IEnumerable<byte> me, bool upperCase = true, string splitShar = ""
|
||||||
|
, int splitInterval = 1)
|
||||||
{
|
{
|
||||||
var ret = BitConverter.ToString(me);
|
var sb = new StringBuilder();
|
||||||
if (!upperCase) {
|
var i = 0;
|
||||||
ret = ret.ToLower(CultureInfo.InvariantCulture);
|
foreach (var c in me.Select(x => x.ToString(upperCase ? "X2" : "x2", CultureInfo.InvariantCulture))) {
|
||||||
|
if (i++ % splitInterval == 0) {
|
||||||
|
sb.Append(splitShar);
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (splitShar != "-") {
|
return sb.ToString();
|
||||||
ret = ret.Replace("-", splitShar ?? string.Empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -369,7 +369,7 @@ public static partial class StringExtensions
|
|||||||
/// <returns>掩码后的手机号</returns>
|
/// <returns>掩码后的手机号</returns>
|
||||||
public static string MaskMobile(this string me)
|
public static string MaskMobile(this string me)
|
||||||
{
|
{
|
||||||
return MyRegex().Replace(me, "$1****$2");
|
return RegexMobile().Replace(me, "$1****$2");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -444,7 +444,7 @@ public static partial class StringExtensions
|
|||||||
/// <returns>处理之后的字符串</returns>
|
/// <returns>处理之后的字符串</returns>
|
||||||
public static string RemoveHtmlTag(this string me)
|
public static string RemoveHtmlTag(this string me)
|
||||||
{
|
{
|
||||||
return MyRegex1().Replace(me, string.Empty);
|
return RegexHtmlTag().Replace(me, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -473,7 +473,7 @@ public static partial class StringExtensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static string Snakecase(this string me)
|
public static string Snakecase(this string me)
|
||||||
{
|
{
|
||||||
return MyRegex2().Replace(me, "-$1").ToLower(CultureInfo.InvariantCulture).TrimStart('-');
|
return RegexUpperCaseLetter().Replace(me, "-$1").ToLower(CultureInfo.InvariantCulture).TrimStart('-');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -507,6 +507,16 @@ public static partial class StringExtensions
|
|||||||
return ret == me ? ret : ret.TrimSpaces();
|
return ret == me ? ret : ret.TrimSpaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将\ux0000 、 %u0000 、 &#x0000; 编码转换成可读字符串
|
||||||
|
/// </summary>
|
||||||
|
public static string UnicodeDe(this string me)
|
||||||
|
{
|
||||||
|
const string replacement = "&#x$1;";
|
||||||
|
return me.Contains(@"\u") ? RegexBacksLantUnicode().Replace(me, replacement).HtmlDe() :
|
||||||
|
me.Contains(@"%u") ? RegexPercentUnicode().Replace(me, replacement).HtmlDe() : me.HtmlDe();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// url编码
|
/// url编码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -542,12 +552,18 @@ public static partial class StringExtensions
|
|||||||
.ToLower(CultureInfo.CurrentCulture);
|
.ToLower(CultureInfo.CurrentCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
[GeneratedRegex("^(\\d{3})\\d{4}(\\d{4})$")]
|
[GeneratedRegex("\\\\u([a-fA-F0-9]{4})")]
|
||||||
private static partial Regex MyRegex();
|
private static partial Regex RegexBacksLantUnicode();
|
||||||
|
|
||||||
[GeneratedRegex("<[^>]*>")]
|
[GeneratedRegex("<[^>]*>")]
|
||||||
private static partial Regex MyRegex1();
|
private static partial Regex RegexHtmlTag();
|
||||||
|
|
||||||
|
[GeneratedRegex("^(\\d{3})\\d{4}(\\d{4})$")]
|
||||||
|
private static partial Regex RegexMobile();
|
||||||
|
|
||||||
|
[GeneratedRegex("\\\\u([a-fA-F0-9]{4})")]
|
||||||
|
private static partial Regex RegexPercentUnicode();
|
||||||
|
|
||||||
[GeneratedRegex("([A-Z])")]
|
[GeneratedRegex("([A-Z])")]
|
||||||
private static partial Regex MyRegex2();
|
private static partial Regex RegexUpperCaseLetter();
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user