Skip to content

Commit

Permalink
Merge pull request #8 from j4587698/dev-os
Browse files Browse the repository at this point in the history
添加Os系统类型
  • Loading branch information
j4587698 authored Feb 17, 2023
2 parents 407260a + 46463f9 commit 9ce7182
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Jx.Toolbox.HtmlTools/Jx.Toolbox.HtmlTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AngleSharp" Version="0.17.1" />
<PackageReference Include="AngleSharp" Version="1.0.1" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions Jx.Toolbox/Extensions/StringExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,15 @@ public static string FirstLetterToLower(this string str)
{
return str.Remove(1).ToLower() + str.Substring(1);
}

/// <summary>
/// 扩展Trim方法,避免null报错
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string TrimEx(this string str)
{
return str == null ? string.Empty : str.Trim();
}
}
}
2 changes: 1 addition & 1 deletion Jx.Toolbox/Jx.Toolbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageProjectUrl>https://github.com/j4587698/Jx.Toolbox</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>tool</PackageTags>
<PackageVersion>0.3.2</PackageVersion>
<PackageVersion>0.3.3</PackageVersion>
</PropertyGroup>

</Project>
38 changes: 38 additions & 0 deletions Jx.Toolbox/Utils/Os.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Runtime.InteropServices;

namespace Jx.Toolbox.Utils
{
/// <summary>
/// 系统类型
/// </summary>
public static class Os
{
/// <summary>
/// 是否是Windows系统
/// </summary>
/// <returns></returns>
public static bool IsWindows()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
}

/// <summary>
/// 是否是Linux系统
/// </summary>
/// <returns></returns>
public static bool IsLinux()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
}

/// <summary>
/// 是否是MaxOs系统
/// </summary>
/// <returns></returns>
public static bool IsMacOs()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
}

}
}
25 changes: 25 additions & 0 deletions Jx.Toolbox/Utils/ProcessUtil.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ Properties扩展类,用于简单的Properties文件独写,可以快速将类
Properties.Serialize(要序列化的类); // 将类序列化为Properties字符串
```

Os
操作系统类型,用于判断当前操作系统类型
```
Os.IsWindows(); // 是否为Windows
Os.IsLinux(); // 是否为Linux
Os.IsMacOs(); // 是否为MacOS
```

## 扩展库

StringExtension
Expand All @@ -65,6 +73,7 @@ StringExtension
"字符串".ToUnderLine(); // 驼峰转下划线
"字符串".FirstLetterToLower(); // 字符串首字母小写
"字符串".FirstLetterToUpper(); // 字符串首字母大写
"字符串".TrimEx(); // 安全的Trim,如果字符串为null,则返回string.Empty
```

ObjectExtension
Expand Down

0 comments on commit 9ce7182

Please sign in to comment.