-
Notifications
You must be signed in to change notification settings - Fork 862
.NET: Update analyzers for .NET 10 SDK #2611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR updates the codebase to leverage .NET 10 SDK analyzers and modern C# language features. The changes primarily focus on adopting collection expressions, pattern matching enhancements, switch expressions, and performance improvements through logging guard clauses.
Key Changes:
- Updated
AnalysisLevelfromlatest/AllEnabledByDefaultto10.0-allfor .NET 10 SDK compatibility - Modernized collection initialization syntax using collection expressions (
[]instead ofnew List<T>(),Array.Empty<T>(), etc.) - Added logging guard clauses (
IsEnabledchecks) to prevent expensive logging argument evaluation when logging is disabled - Converted to modern pattern matching (
is not (Type1 or Type2), switch expressions)
Reviewed changes
Copilot reviewed 41 out of 41 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/Directory.Build.props | Updated AnalysisLevel to target .NET 10 with all analyzers enabled |
| dotnet/tests/.editorconfig | Added suppressions for new .NET 10 analyzers in test projects (CA1822, CA1873, CA1875, CA2249) |
| dotnet/samples/.editorconfig | Added CA1873 suppression for sample projects |
| dotnet/src/Microsoft.Agents.AI/Memory/ChatHistoryMemoryProvider.cs | Added logging guard clauses for performance optimization |
| dotnet/src/Microsoft.Agents.AI/Data/TextSearchProvider.cs | Added logging guard clauses for performance optimization |
| dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilder.cs | Converted to collection expression syntax |
| dotnet/src/Microsoft.Agents.AI.Workflows/Execution/FanInEdgeState.cs | Converted to collection expression syntax |
| dotnet/src/Microsoft.Agents.AI.Workflows/Execution/EdgeConnection.cs | Converted to collection expression syntax |
| dotnet/src/Microsoft.Agents.AI.Workflows/Checkpointing/RepresentationExtensions.cs | Converted to collection expression syntax |
| dotnet/src/Microsoft.Agents.AI.Purview/ScopedContentProcessor.cs | Converted to switch expression and collection expression syntax |
| dotnet/src/Microsoft.Agents.AI.Purview/PurviewWrapper.cs | Added logging guard clauses |
| dotnet/src/Microsoft.Agents.AI.Purview/PurviewClient.cs | Added logging guard clauses and collection expression syntax |
| dotnet/src/Microsoft.Agents.AI.Purview/PurviewAppLocation.cs | Converted to switch expression |
| dotnet/src/Microsoft.Agents.AI.Purview/ChannelHandler.cs | Added logging guard clauses |
| dotnet/src/Microsoft.Agents.AI.Purview/BackgroundJobRunner.cs | Added logging guard clauses |
| dotnet/src/Microsoft.Agents.AI.Mem0/Mem0Provider.cs | Added logging guard clauses |
| dotnet/src/Microsoft.Agents.AI.Mem0/Mem0Client.cs | Converted to collection expression syntax |
| dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/HostedAgentResponseExecutor.cs | Added logging guard clauses |
| dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIServerSentEventsResult.cs | Removed unused StatusCode property |
| dotnet/src/Microsoft.Agents.AI.DurableTask/State/DurableAgentStateFunctionCallContent.cs | Changed from ToImmutableDictionary to ToDictionary |
| dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgent.cs | Simplified object initialization syntax |
| dotnet/src/Microsoft.Agents.AI.DevUI/DevUIMiddleware.cs | Added logging guard clauses |
| dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosChatMessageStore.cs | Updated to use JsonElement.Deserialize extension method |
| dotnet/src/Microsoft.Agents.AI.CopilotStudio/ActivityProcessor.cs | Added logging guard clause |
| dotnet/src/Microsoft.Agents.AI.AGUI/AGUIChatClient.cs | Added logging guard clauses |
| dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs | Converted to pattern matching with or |
| dotnet/samples/GettingStarted/AgentProviders/Agent_With_GoogleGemini/GeminiChatClient.cs | Extensive conversion to collection expression syntax |
| dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestEchoAgent.cs | Converted to collection expression syntax |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/Memory/ChatHistoryMemoryProviderTests.cs | Updated test assertion to use IsType with exactMatch parameter |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/Data/TextSearchProviderTests.cs | Converted test data to collection expression syntax |
| dotnet/tests/Microsoft.Agents.AI.Purview.UnitTests/ScopedContentProcessorTests.cs | Converted test data to collection expression syntax |
| dotnet/tests/Microsoft.Agents.AI.Purview.UnitTests/PurviewClientTests.cs | Converted test data to collection expression syntax |
| dotnet/tests/Microsoft.Agents.AI.Mem0.UnitTests/Mem0ProviderTests.cs | Converted test data to collection expression syntax and updated assertions |
| dotnet/tests/Microsoft.Agents.AI.Mem0.IntegrationTests/Mem0ProviderTests.cs | Converted test data to collection expression syntax |
| dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests/AGUIServerSentEventsResultTests.cs | Removed assertion for deleted StatusCode property |
| dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosCheckpointStoreTests.cs | Converted to modern pattern matching syntax |
| dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosChatMessageStoreTests.cs | Converted to collection expression syntax |
| dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AzureAIProjectChatClientExtensionsTests.cs | Simplified MockPipelineResponse to use auto-property |
| dotnet/tests/Microsoft.Agents.AI.AGUI.UnitTests/AGUIChatClientTests.cs | Converted to collection spread expression |
| dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/Extensions/A2AArtifactExtensionsTests.cs | Converted to collection expression syntax |
| dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs | Converted to pattern matching with or |
Comments suppressed due to low confidence (1)
dotnet/src/Microsoft.Agents.AI.Mem0/Mem0Provider.cs:177
- The nested
IsEnabledcheck forLogLevel.Traceis redundant and creates a logic issue. Similar to the TextSearchProvider issue, this nests the Trace check inside the Information check, which means Trace logs will only be written if Information level is enabled. Since Trace is a more verbose level than Information, this should be a separate independent check. The checks should be:
if (this._logger?.IsEnabled(LogLevel.Information) is true)
{
this._logger.LogInformation(...);
}
if (outputMessageText is not null && this._logger?.IsEnabled(LogLevel.Trace) is true)
{
this._logger.LogTrace(...);
} if (this._logger?.IsEnabled(LogLevel.Information) is true)
{
this._logger.LogInformation(
"Mem0AIContextProvider: Retrieved {Count} memories. ApplicationId: '{ApplicationId}', AgentId: '{AgentId}', ThreadId: '{ThreadId}', UserId: '{UserId}'.",
memories.Count,
this._searchScope.ApplicationId,
this._searchScope.AgentId,
this._searchScope.ThreadId,
this.SanitizeLogData(this._searchScope.UserId));
if (outputMessageText is not null && this._logger.IsEnabled(LogLevel.Trace))
{
this._logger.LogTrace(
"Mem0AIContextProvider: Search Results\nInput:{Input}\nOutput:{MessageText}\nApplicationId: '{ApplicationId}', AgentId: '{AgentId}', ThreadId: '{ThreadId}', UserId: '{UserId}'.",
this.SanitizeLogData(queryText),
this.SanitizeLogData(outputMessageText),
this._searchScope.ApplicationId,
this._searchScope.AgentId,
this._searchScope.ThreadId,
this.SanitizeLogData(this._searchScope.UserId));
}
}
dotnet/src/Microsoft.Agents.AI.DurableTask/State/DurableAgentStateFunctionCallContent.cs
Show resolved
Hide resolved
7592316 to
228b76c
Compare
No description provided.