📄 impshelper.cs
字号:
namespace Imps.Utils
{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Xml;
public static class ImpsHelper
{
private static string _mobileNoDist = string.Empty;
private static List<MobileNoLimited> mobileNoLimited = new List<MobileNoLimited>();
public static DateTime AgeToBirthday(int age)
{
return new DateTime(DateTime.Now.Year - age, 1, 1);
}
public static DateTime AgeToBirthday(int age, int month, int day)
{
int year = DateTime.Now.Year - age;
if (((day == 0x1d) && (month == 2)) && !DateTime.IsLeapYear(year))
{
day--;
}
DateTime time = new DateTime(year, month, day);
DateTime today = DateTime.Today;
int num2 = today.Month;
int num3 = today.Day;
if ((month <= num2) && ((month != num2) || (day <= num3)))
{
return time;
}
return time.AddYears(-1);
}
public static int BirthdayToAge(DateTime birthday)
{
return BirthdayToAge(birthday, DateTime.Today);
}
public static int BirthdayToAge(DateTime birthday, DateTime today)
{
int month = birthday.Month;
int day = birthday.Day;
int num3 = today.Month;
int num4 = today.Day;
int num5 = today.Year - birthday.Year;
if (num5 <= 0)
{
return 0;
}
if ((month > num3) || ((month == num3) && (day > num4)))
{
num5--;
}
return num5;
}
public static char Char2WideChar(char c)
{
if ((c >= '!') && (c < '~'))
{
c = (char) (c + 0xfee0);
}
return c;
}
public static bool IsBirthdayValid(DateTime birthday, int minAge, int maxAge)
{
return IsBirthdayValid(birthday, minAge, maxAge, DateTime.Today);
}
public static bool IsBirthdayValid(DateTime birthday, int minAge, int maxAge, DateTime today)
{
if (birthday.Year == 0x76c)
{
return true;
}
int num = BirthdayToAge(birthday, today);
if (num >= minAge)
{
return (num <= maxAge);
}
return false;
}
public static bool IsCmccMobileNo(long mobileNo)
{
return IsValidMoileNo(mobileNo);
}
public static bool IsCmccMobileNo(string mobileNo)
{
return IsValidMoileNo(mobileNo);
}
public static bool IsSid(long id)
{
if (id >= 0x3e8)
{
return (id < 0x2540be400);
}
return false;
}
private static bool IsValidMoileNo(long mobileNo)
{
try
{
if ((mobileNo >= 0x2540be400) && (mobileNo <= 0x174876e7ff))
{
bool flag = true;
List<MobileNoLimited>.Enumerator enumerator = mobileNoLimited.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
MobileNoLimited limited = enumerator.get_Current();
flag = false;
if ((mobileNo >= limited.StartNo) && (mobileNo <= limited.EndNo))
{
return true;
}
}
}
finally
{
enumerator.Dispose();
}
return flag;
}
return false;
}
catch
{
return false;
}
}
private static bool IsValidMoileNo(string mobileNo)
{
long num;
if (TryParseMobileNo(mobileNo, out num))
{
return IsValidMoileNo(num);
}
return false;
}
public static bool TryParseMobileNo(string s, out long mobileNo)
{
mobileNo = 0;
if (s.Length > 13)
{
if (!s.StartsWith("+86"))
{
if (!s.StartsWith("0086"))
{
return false;
}
s = s.Substring(4).Trim();
}
else
{
s = s.Substring(3).Trim();
}
}
if ((s.Length == 11) && !s.StartsWith("0"))
{
return long.TryParse(s, ref mobileNo);
}
return false;
}
public static bool TryParseMobileNoExtend(string s, out long mobileNo)
{
mobileNo = 0;
if (string.IsNullOrEmpty(s))
{
return false;
}
if (s.Contains(";"))
{
s = s.Split(new char[] { ';' })[0];
}
s = s.Trim();
if (s.Length < 11)
{
return false;
}
if (s.Length > 11)
{
s = s.Substring(s.Length - 11, 11);
}
return TryParseMobileNo(s, out mobileNo);
}
public static bool TryParseSid(string s, out int sid)
{
sid = 0;
if ((s.Length > 4) && (s.Length < 11))
{
return int.TryParse(s, ref sid);
}
return false;
}
public static bool TryParseSidOrCmccMobileNo(string s, out long nbr)
{
nbr = 0;
if (string.IsNullOrEmpty(s) || (s[0] == '0'))
{
return false;
}
if ((s.Length == 11) && IsCmccMobileNo(s))
{
return TryParseMobileNo(s, out nbr);
}
if (s.Length < 11)
{
return long.TryParse(s, ref nbr);
}
return (nbr > 0);
}
public static char WideCharToChar(char c)
{
if ((c >= 0xff01) && (c < 0xff5e))
{
c = (char) (c - 0xfee0);
}
return c;
}
public static string MobileNoDist
{
set
{
try
{
if (!string.IsNullOrEmpty(value) && (value != _mobileNoDist))
{
if (mobileNoLimited == null)
{
mobileNoLimited = new List<MobileNoLimited>();
}
else
{
mobileNoLimited.Clear();
}
_mobileNoDist = value;
XmlDocument document = new XmlDocument();
document.LoadXml(_mobileNoDist);
foreach (XmlNode node2 in document.DocumentElement.ChildNodes)
{
string text = node2.Attributes["v"].Value;
foreach (XmlNode node3 in node2.ChildNodes)
{
MobileNoLimited limited = new MobileNoLimited();
limited.Carrier = text;
long num = 0;
if (long.TryParse(node3.Attributes["s"].Value, ref num))
{
limited.StartNo = num;
num = 0;
if (long.TryParse(node3.Attributes["e"].Value, ref num))
{
limited.EndNo = num;
if (limited.EndNo >= limited.StartNo)
{
mobileNoLimited.Add(limited);
}
}
}
}
}
}
}
catch
{
_mobileNoDist = string.Empty;
mobileNoLimited.Clear();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -