mirror of
https://github.com/nsnail/ns-ext.git
synced 2025-06-20 04:48:17 +08:00
refactor: ♻️ 2.0 (#3)
This commit is contained in:
41
src/backend/NSExt/Extensions/IntExtensions.cs
Normal file
41
src/backend/NSExt/Extensions/IntExtensions.cs
Normal file
@ -0,0 +1,41 @@
|
||||
namespace NSExt.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// IntExtensions
|
||||
/// </summary>
|
||||
public static class IntExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 判断枚举是否包含某个位
|
||||
/// </summary>
|
||||
public static bool HasFlag<T>(this int me, T flag)
|
||||
where T : Enum
|
||||
{
|
||||
return ((long)me).HasFlag(flag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成随机数
|
||||
/// </summary>
|
||||
/// <param name="me">me</param>
|
||||
public static int Rand(this int[] me)
|
||||
{
|
||||
return new Random(Guid.NewGuid().GetHashCode()).Next(me[0], me[1]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ToString 的 Invariant 版本
|
||||
/// </summary>
|
||||
public static string ToInvString(this int me)
|
||||
{
|
||||
return me.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换成ipv4
|
||||
/// </summary>
|
||||
public static string ToIpV4(this int me)
|
||||
{
|
||||
return string.Join(".", BitConverter.GetBytes(me).Reverse());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user