Skip to content

Commit

Permalink
使用 nameof 优化字符串参数
Browse files Browse the repository at this point in the history
  • Loading branch information
gmf520 committed Nov 19, 2023
1 parent 99aa78f commit db32382
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/OSharp.Utils/Reflection/AssemblyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class AssemblyExtensions
/// </summary>
public static string GetFileVersion(this Assembly assembly)
{
assembly.CheckNotNull("assembly");
assembly.CheckNotNull(nameof(assembly));
FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location);
return info.FileVersion;
}
Expand All @@ -38,10 +38,10 @@ public static string GetFileVersion(this Assembly assembly)
/// </summary>
public static string GetProductVersion(this Assembly assembly)
{
assembly.CheckNotNull("assembly");
assembly.CheckNotNull(nameof(assembly));
FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = info.ProductVersion;
if (version.Contains("+"))
if (version?.Contains("+") == true)
{
version = version.ReplaceRegex(@"\+(\w+)?", "");
}
Expand All @@ -64,7 +64,7 @@ public static string GetCliVersion()
CompilationLibrary lib = null;
foreach (string dllName in dllNames)
{
lib = DependencyContext.Default.CompileLibraries.FirstOrDefault(m => m.Name == dllName);
lib = DependencyContext.Default?.CompileLibraries.FirstOrDefault(m => m.Name == dllName);
if (lib != null)
{
break;
Expand All @@ -74,4 +74,4 @@ public static string GetCliVersion()
return cliVersion;
}
}
}
}

0 comments on commit db32382

Please sign in to comment.