diff --git a/Jx.Toolbox.HtmlTools/Jx.Toolbox.HtmlTools.csproj b/Jx.Toolbox.HtmlTools/Jx.Toolbox.HtmlTools.csproj index b4bea4b..8eb7111 100644 --- a/Jx.Toolbox.HtmlTools/Jx.Toolbox.HtmlTools.csproj +++ b/Jx.Toolbox.HtmlTools/Jx.Toolbox.HtmlTools.csproj @@ -15,7 +15,7 @@ - + diff --git a/Jx.Toolbox/Extensions/StringExtension.cs b/Jx.Toolbox/Extensions/StringExtension.cs index e2398ca..500ae5d 100644 --- a/Jx.Toolbox/Extensions/StringExtension.cs +++ b/Jx.Toolbox/Extensions/StringExtension.cs @@ -90,5 +90,15 @@ public static string FirstLetterToLower(this string str) { return str.Remove(1).ToLower() + str.Substring(1); } + + /// + /// 扩展Trim方法,避免null报错 + /// + /// + /// + public static string TrimEx(this string str) + { + return str == null ? string.Empty : str.Trim(); + } } } \ No newline at end of file diff --git a/Jx.Toolbox/Jx.Toolbox.csproj b/Jx.Toolbox/Jx.Toolbox.csproj index 7caf437..611d249 100644 --- a/Jx.Toolbox/Jx.Toolbox.csproj +++ b/Jx.Toolbox/Jx.Toolbox.csproj @@ -9,7 +9,7 @@ https://github.com/j4587698/Jx.Toolbox MIT tool - 0.3.2 + 0.3.3 diff --git a/Jx.Toolbox/Utils/Os.cs b/Jx.Toolbox/Utils/Os.cs new file mode 100644 index 0000000..95ce915 --- /dev/null +++ b/Jx.Toolbox/Utils/Os.cs @@ -0,0 +1,38 @@ +using System.Runtime.InteropServices; + +namespace Jx.Toolbox.Utils +{ + /// + /// 系统类型 + /// + public static class Os + { + /// + /// 是否是Windows系统 + /// + /// + public static bool IsWindows() + { + return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + } + + /// + /// 是否是Linux系统 + /// + /// + public static bool IsLinux() + { + return RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + } + + /// + /// 是否是MaxOs系统 + /// + /// + public static bool IsMacOs() + { + return RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + } + + } +} \ No newline at end of file diff --git a/Jx.Toolbox/Utils/ProcessUtil.cs b/Jx.Toolbox/Utils/ProcessUtil.cs new file mode 100644 index 0000000..b754e55 --- /dev/null +++ b/Jx.Toolbox/Utils/ProcessUtil.cs @@ -0,0 +1,25 @@ +using System.Diagnostics; + +namespace Jx.Toolbox.Utils +{ + public class ProcessUtil + { + public static void KillProcess(string processName) + { + foreach (var process in Process.GetProcessesByName(processName)) + { + process.Kill(); + } + } + + public static void KillProcess(int processId) + { + Process.GetProcessById(processId).Kill(); + } + + public static void StartProcess(string fileName, string arguments) + { + Process.Start(fileName, arguments); + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index 8a69832..9d9a842 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,14 @@ Properties扩展类,用于简单的Properties文件独写,可以快速将类 Properties.Serialize(要序列化的类); // 将类序列化为Properties字符串 ``` +Os +操作系统类型,用于判断当前操作系统类型 +``` +Os.IsWindows(); // 是否为Windows +Os.IsLinux(); // 是否为Linux +Os.IsMacOs(); // 是否为MacOS +``` + ## 扩展库 StringExtension @@ -65,6 +73,7 @@ StringExtension "字符串".ToUnderLine(); // 驼峰转下划线 "字符串".FirstLetterToLower(); // 字符串首字母小写 "字符串".FirstLetterToUpper(); // 字符串首字母大写 +"字符串".TrimEx(); // 安全的Trim,如果字符串为null,则返回string.Empty ``` ObjectExtension