修复了枚举状态扩展中隐藏的缺陷;

添加了在列表中随机获取项目的扩展;
添加了数值转中文格式的繁体字库;
This commit is contained in:
2023-10-30 09:40:45 +08:00
parent e293c5592d
commit 42d3fbc69f
3 changed files with 33 additions and 11 deletions
+10 -10
View File
@@ -188,7 +188,7 @@ namespace XericLibrary.Runtime.MacroLibrary
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EnumGreater(this Enum target)
{
return target.EnumToInt32() > 0;
return target.EnumToInt32() != 0;
}
/// <summary>
@@ -198,7 +198,7 @@ namespace XericLibrary.Runtime.MacroLibrary
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EnumGreater(this Enum target, Enum value)
{
return (target.EnumToInt32() & value.EnumToInt32()) > 0;
return (target.EnumToInt32() & value.EnumToInt32()) != 0;
}
/// <summary>
@@ -208,7 +208,7 @@ namespace XericLibrary.Runtime.MacroLibrary
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EnumGreater1(this Enum target)
{
return (target.EnumToInt32() & 01) > 0;
return (target.EnumToInt32() & 01) != 0;
}
/// <summary>
@@ -218,7 +218,7 @@ namespace XericLibrary.Runtime.MacroLibrary
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EnumGreater2(this Enum target)
{
return (target.EnumToInt32() & 02) > 0;
return (target.EnumToInt32() & 02) != 0;
}
/// <summary>
@@ -228,7 +228,7 @@ namespace XericLibrary.Runtime.MacroLibrary
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EnumGreater3(this Enum target)
{
return (target.EnumToInt32() & 04) > 0;
return (target.EnumToInt32() & 04) != 0;
}
/// <summary>
@@ -238,7 +238,7 @@ namespace XericLibrary.Runtime.MacroLibrary
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EnumGreater4(this Enum target)
{
return (target.EnumToInt32() & 010) > 0;
return (target.EnumToInt32() & 010) != 0;
}
/// <summary>
@@ -248,7 +248,7 @@ namespace XericLibrary.Runtime.MacroLibrary
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EnumGreater5(this Enum target)
{
return (target.EnumToInt32() & 020) > 0;
return (target.EnumToInt32() & 020) != 0;
}
/// <summary>
@@ -258,7 +258,7 @@ namespace XericLibrary.Runtime.MacroLibrary
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EnumGreater6(this Enum target)
{
return (target.EnumToInt32() & 030) > 0;
return (target.EnumToInt32() & 030) != 0;
}
/// <summary>
@@ -268,7 +268,7 @@ namespace XericLibrary.Runtime.MacroLibrary
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EnumGreater7(this Enum target)
{
return (target.EnumToInt32() & 040) > 0;
return (target.EnumToInt32() & 040) != 0;
}
/// <summary>
@@ -278,7 +278,7 @@ namespace XericLibrary.Runtime.MacroLibrary
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EnumGreater8(this Enum target)
{
return (target.EnumToInt32() & 0100) > 0;
return (target.EnumToInt32() & 0100) != 0;
}
/// <summary>
+18
View File
@@ -85,5 +85,23 @@ namespace XericLibrary.Runtime.MacroLibrary
}
#endregion
#region
/// <summary>
/// 获取列表中随机顺序的对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
/// <param name="count">需要采样的数量</param>
/// <returns></returns>
public static IEnumerable<T> GetRandom<T>(this List<T> list, int count = -1)
{
var index = FisherYatesShuffle(list.Count, count <= 0 ? list.Count : count);
for(int i = 0; i < index.Count; i++)
yield return list[index[i]];
}
#endregion
}
}
+5 -1
View File
@@ -62,6 +62,11 @@ namespace XericLibrary.Runtime.MacroLibrary
private static readonly string[] chineseDigit = new string[]
{ "","十","百","千","万","十","百","千","亿","十","百","千","亿"};
private static readonly string[] chineseNumber_ComplexFont = new string[]
{"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
private static readonly string[] chineseDigit_ComplexFont = new string[]
{ "","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟","亿"};
/// <summary>
/// 将一个数值转为中文小写格式;
/// </summary>
@@ -98,7 +103,6 @@ namespace XericLibrary.Runtime.MacroLibrary
/// 将一个数值转为中文小写格式,并确保读写格式满足日常使用;
/// 比如 510会读成五百一十,9009会读成九千零九,
/// 最大支持到九千亿,理论上并不是它的极限,只要继续套格式即可。
/// 不过缺点是在读10,11时,会读成一十,一十一,需要额外处理一下以符合阅读习惯
/// </summary>
/// <param name="number"></param>
/// <returns></returns>