123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Reflection;
- namespace CSharpUtil
- {
- static class CommUtils
- {
- public static string var_dump(this object info)
- {
- StringBuilder sb = new StringBuilder();
- Type t = info.GetType();
- PropertyInfo[] props = t.GetProperties();
- sb.AppendFormat("{0,-18} {1}", "Name", "Value");
- sb.AppendLine();
- foreach (PropertyInfo prop in props)
- {
- sb.AppendFormat("{0,-18} {1}", prop.Name, prop.GetValue(info, null).ToString());
- sb.AppendLine();
- }
- return sb.ToString();
- }
- }
- #region ` 字符串扩展 `
- public static class StringExtensionUtils
- {
- /// <summary>
- /// 字符串扩展:正则替换方法
- /// </summary>
- /// <param name="str"></param>
- /// <param name="pattern"></param>
- /// <param name="replacement"></param>
- /// <returns></returns>
- public static string RegReplace(this string str, string pattern, string replacement)
- {
- return Regex.Replace(str, pattern, replacement);
- }
- readonly static Regex reg = new Regex(@"(?<=""|:|,|\{|\}|\[|\])\s+(?=""|:|,|\{|\}|\[|\]|null|\d)");
- /// <summary>
- /// 字符串扩展:压缩json字符串的功能(去除多余的空白字符)
- /// </summary>
- /// <param name="str"></param>
- /// <returns></returns>
- [Obsolete("鉴于次函数的性能问题,不建议继续使用.--gwang 2022.3.4")]
- public static string JsMin(this string str)
- {
- return reg.Replace(str, "");
- }
- }
- #endregion
- }
|