今天给大家推荐一个C#开发工具箱,涵盖了所有常用操作类,体积小、功能强大。
C# 开发工具箱。大都是静态类,加密解密,反射操作,权重随机筛选算法,分布式短id,表达式树,linq扩展,文件压缩,多线程下载和FTP客户端,硬件信息,字符串扩展方法,日期时间扩展操作,中国农历,大文件拷贝,图像裁剪,验证码,断点续传,集合扩展、Excel导出等常用封装。诸多功能集一身,代码量不到2MB!
开发工具:VisualStudio2019
SDK:.NET Core 2.1.0
字符串格式校验
bool isEmAIl="337845818@qq.com".MatchEmail(); // 可在Appsetting.json中添加EmailDomainWhiteList和EmailDomainBlockList配置邮箱域名黑白名单,逗号分隔,如"EmailDomainBlockList": "^w{1,5}@qq.com,^w{1,5}@163.com,^w{1,5}@gmail.com,^w{1,5}@outlook.com",bool isInetAddress = "114.114.114.114".MatchInetAddress();bool isUrl = "http://ldqk.org/20/history".MatchUrl();bool isPhoneNumber = "15205201520".MatchPhoneNumber();bool isIdentifyCard = "312000199502230660".MatchIdentifyCard();// 校验中国大陆身份证号bool isCNPatentNumber = "200410018477.9".MatchCNPatentNumber(); // 校验中国专利申请号或专利号,是否带校验位,校验位前是否带“.”,都可以校验,待校验的号码前不要带CN、ZL字样的前缀
任意进制转换
NumberFormater nf = new NumberFormater(36);//内置2-62进制的转换//NumberFormater nf = new NumberFormater("0123456789abcdefghijklmnopqrstuvwxyz");// 自定义进制字符,可用于生成验证码string s36 = nf.ToString(12345678);long num = nf.FromString("7clzi");Console.WriteLine("12345678的36进制是:" + s36); // 7clziConsole.WriteLine("36进制的7clzi是:" + num); // 12345678var s = new NumberFormater(62).ToString(new Random().Next(100000, int.MaxValue)); //配合随机数生成随机字符串
唯一ID生成
var token=Stopwatch.GetTimestamp().ToBinary(36);
var set = new HashSet<string>();double time = HiPerfTimer.Execute(() =>{for (int i = 0; i < 1000000; i++){set.Add(Stopwatch.GetTimestamp().ToBinary(36));}});Console.WriteLine(set.Count==1000000);//TrueConsole.WriteLine("产生100w个id耗时"+time+"s");//1.6639039s
农历转换
ChineseCalendar.CustomHolidays.Add(DateTime.Parse("2018-12-31"),"元旦节");//自定义节假日ChineseCalendar today = new ChineseCalendar(DateTime.Parse("2018-12-31"));Console.WriteLine(today.ChineseDateString);// 二零一八年十一月廿五Console.WriteLine(today.AnimalString);// 生肖:狗Console.WriteLine(today.GanZhiDateString);// 干支:戊戌年甲子月丁酉日Console.WriteLine(today.DateHoliday);// 获取按公历计算的节假日
加密解密
var enc="123456".MDString();// MD5var enc="123456".MDString("abc");// MD5加盐var enc="123456".MDString2();// MD5两次var enc="123456".MDString2("abc");// MD5两次加盐var enc="123456".MDString3();// MD5三次var enc="123456".MDString3("abc");// MD5三次加盐string aes = "123456".AESEncrypt();// AES加密为密文string s = aes.AESDecrypt(); //AES解密为明文string aes = "123456".AESEncrypt("abc");// AES密钥加密为密文string s = aes.AESDecrypt("abc"); //AES密钥解密为明文string enc = "123456".DesEncrypt();// DES加密为密文string s = enc.DesDecrypt(); //DES解密为明文string enc = "123456".DesEncrypt("abcdefgh");// DES密钥加密为密文string s = enc.DesDecrypt("abcdefgh"); //DES密钥解密为明文RsaKey rsaKey = RsaCrypt.GenerateRsaKeys();// 生成RSA密钥对string encrypt = "123456".RSAEncrypt(rsaKey.PublicKey);// 公钥加密string s = encrypt.RSADecrypt(rsaKey.PrivateKey);// 私钥解密string s = "123".Crc32();// 生成crc32摘要string s = "123".Crc64();// 生成crc64摘要