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
{
///
/// 字符串扩展:正则替换方法
///
///
///
///
///
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)");
///
/// 字符串扩展:压缩json字符串的功能(去除多余的空白字符)
///
///
///
[Obsolete("鉴于次函数的性能问题,不建议继续使用.--gwang 2022.3.4")]
public static string JsMin(this string str)
{
return reg.Replace(str, "");
}
}
#endregion
}