Skip to content

Commit 71b79b0

Browse files
Copilotjongalloway
andcommitted
Apply code style improvements from review feedback
Address nitpick suggestions to improve code readability and conventions: - Use LastOrDefault()?.Version instead of indexed access for better idiomatic C# - Cache Environment.NewLine.Length as static readonly field to avoid repeated property access - Add System.IO using and use Path.Combine instead of System.IO.Path.Combine for consistency These changes maintain identical functionality while following C# conventions. Co-authored-by: jongalloway <[email protected]>
1 parent d2b107f commit 71b79b0

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

DotNetMcp/DotNetCommandExecutor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace DotNetMcp;
1111
public static class DotNetCommandExecutor
1212
{
1313
private const int MaxOutputCharacters = 1_000_000;
14+
private static readonly int NewLineLength = Environment.NewLine.Length;
1415

1516
/// <summary>
1617
/// Execute a dotnet command with full output handling, logging, and truncation support.
@@ -43,7 +44,7 @@ public static async Task<string> ExecuteCommandAsync(string arguments, ILogger?
4344
if (e.Data != null)
4445
{
4546
// Check if adding this line would exceed the limit
46-
int projectedLength = output.Length + e.Data.Length + Environment.NewLine.Length;
47+
int projectedLength = output.Length + e.Data.Length + NewLineLength;
4748
if (projectedLength < MaxOutputCharacters)
4849
{
4950
output.AppendLine(e.Data);
@@ -61,7 +62,7 @@ public static async Task<string> ExecuteCommandAsync(string arguments, ILogger?
6162
if (e.Data != null)
6263
{
6364
// Check if adding this line would exceed the limit
64-
int projectedLength = error.Length + e.Data.Length + Environment.NewLine.Length;
65+
int projectedLength = error.Length + e.Data.Length + NewLineLength;
6566
if (projectedLength < MaxOutputCharacters)
6667
{
6768
error.AppendLine(e.Data);

DotNetMcp/DotNetResources.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.IO;
12
using System.Text.Json;
23
using Microsoft.Extensions.Logging;
34
using ModelContextProtocol.Server;
@@ -52,14 +53,14 @@ public async Task<string> GetSdkInfo()
5253
{
5354
var version = parts[0].Trim();
5455
var path = parts[1].TrimEnd(']').Trim();
55-
sdks.Add(new SdkInfo(version, System.IO.Path.Combine(path, version)));
56+
sdks.Add(new SdkInfo(version, Path.Combine(path, version)));
5657
}
5758
}
5859

5960
var response = new
6061
{
6162
sdks,
62-
latestSdk = sdks.Count > 0 ? sdks[sdks.Count - 1].Version : null
63+
latestSdk = sdks.LastOrDefault()?.Version
6364
};
6465

6566
return JsonSerializer.Serialize(response, new JsonSerializerOptions { WriteIndented = true });
@@ -99,7 +100,7 @@ public async Task<string> GetRuntimeInfo()
99100
var name = nameAndVersion[0];
100101
var version = nameAndVersion[1];
101102
var path = parts[1].TrimEnd(']').Trim();
102-
runtimes.Add(new RuntimeInfo(name, version, System.IO.Path.Combine(path, version)));
103+
runtimes.Add(new RuntimeInfo(name, version, Path.Combine(path, version)));
103104
}
104105
}
105106
}

0 commit comments

Comments
 (0)