XmlFix is a comprehensive suite of Roslyn-based analyzers and code fix providers designed to enhance code quality, maintainability, and performance in .NET applications. The project implements Microsoft's recommended coding practices through automated analysis and intelligent code fixes, helping development teams maintain consistent, high-quality codebases.
- Key Features
- Implemented Analyzers
- Installation
- Usage
- Configuration
- Architecture
- Testing
- Development
- Contributing
- Support
- License
- Automated Code Analysis: Real-time detection of code quality issues during development
- Intelligent Code Fixes: One-click fixes with context-aware code generation
- Microsoft Best Practices: Implementation of official CA (Code Analysis) warnings
- IDE Integration: Seamless integration with Visual Studio, VS Code, and Rider
- CI/CD Ready: GitHub Actions workflow for automated builds and testing
- High Test Coverage: 93.97% test coverage (187/199 tests passing)
- Performance Optimized: Concurrent analysis with minimal build impact
- .NET Standard 2.0: Broad compatibility across all modern .NET platforms
- Comprehensive Testing: Full test suites for each analyzer and code fix
- Production Ready: Version 0.1.0 with stable API and reliable fixes
Diagnostic ID: XFIX001
Category: Design
Default Severity: Warning
Detects methods that should be implemented as properties based on Microsoft's design guidelines.
- Parameterless methods with non-void return types
- Methods prefixed with "Get" that return simple values
- Methods that represent data rather than operations
Automatically converts qualifying methods to properties with appropriate accessors.
Example:
// Before
public string GetName()
{
return _name;
}
// After (with code fix applied)
public string Name => _name;Diagnostic ID: XFIX002
Category: Globalization
Default Severity: Warning
Enforces explicit StringComparison parameters in string operations to avoid culture-specific bugs and improve performance.
- String methods without StringComparison parameter
- Methods: StartsWith, EndsWith, Equals, IndexOf, LastIndexOf, Contains, Compare
Adds appropriate StringComparison parameter based on context:
StringComparison.Ordinalfor technical comparisonsStringComparison.OrdinalIgnoreCasefor case-insensitive technical comparisonsStringComparison.CurrentCulturefor user-facing text
Example:
// Before
if (text.StartsWith("Error"))
// After (with code fix applied)
if (text.StartsWith("Error", StringComparison.Ordinal))Diagnostic ID: XFIX003
Category: Performance
Default Severity: Info
Promotes the use of LoggerMessage delegates for high-performance logging scenarios.
- Direct logger method calls with string interpolation
- Logger calls in performance-critical paths
- Frequent logging operations
Converts logger calls to pre-compiled LoggerMessage delegates for improved performance.
Example:
// Before
_logger.LogInformation($"Processing item {id}");
// After (with code fix applied)
private static readonly Action<ILogger, string, Exception?> _logProcessingItem =
LoggerMessage.Define<string>(
LogLevel.Information,
new EventId(1001),
"Processing item {Id}");
// Usage
_logProcessingItem(_logger, id, null);Diagnostic ID: XDOC001
Category: Documentation
Default Severity: Warning
Ensures comprehensive XML documentation coverage for public APIs.
- Public types, methods, properties, fields, and events without documentation
- Interface implementations missing documentation
- Override methods without documentation
- Generate contextual XML documentation
- Add
<inheritdoc/>for interface implementations and overrides
Example:
// Before
public class UserService
{
public User GetUser(int id) { }
}
// After (with code fix applied)
/// <summary>
/// Service for managing user operations.
/// </summary>
public class UserService
{
/// <summary>
/// Gets the user by identifier.
/// </summary>
/// <param name="id">The user identifier.</param>
/// <returns>The user if found; otherwise, null.</returns>
public User GetUser(int id) { }
}Install-Package XmlFix.Analyzers -Version 0.1.0dotnet add package XmlFix.Analyzers --version 0.1.0<ItemGroup>
<PackageReference Include="XmlFix.Analyzers" Version="0.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>Once installed, the analyzers automatically run during build and in your IDE. Warnings appear in the Error List (Visual Studio) or Problems panel (VS Code).
- Hover over the diagnostic squiggle
- Click the light bulb icon or press
Ctrl+. - Select the appropriate fix from the menu
- Place cursor on the diagnostic
- Press
Ctrl+.or click the light bulb - Choose the fix to apply
# Format and fix code using dotnet format
dotnet format analyzers --severity warnConfigure analyzer behavior through .editorconfig:
root = true
[*.cs]
# PropertyMethod Analyzer
dotnet_diagnostic.XFIX001.severity = warning
# StringComparison Analyzer
dotnet_diagnostic.XFIX002.severity = warning
# LoggerMessage Analyzer
dotnet_diagnostic.XFIX003.severity = suggestion
# XML Documentation Analyzer
dotnet_diagnostic.XDOC001.severity = warning
# Disable in test files
[*Tests.cs]
dotnet_diagnostic.XDOC001.severity = noneFor solution-wide settings, create .globalconfig:
is_global = true
# Default severities
dotnet_diagnostic.XFIX001.severity = warning
dotnet_diagnostic.XFIX002.severity = warning
dotnet_diagnostic.XFIX003.severity = info
dotnet_diagnostic.XDOC001.severity = warningXmlFix/
├── XmlFix.Analyzers/ # Core analyzer implementations
│ ├── Common/ # Shared utilities and constants
│ │ ├── AnalyzerConstants.cs # Diagnostic IDs and constants
│ │ └── SyntaxHelper.cs # Syntax analysis utilities
│ ├── PropertyMethodAnalyzer.cs # CA1024 implementation
│ ├── PropertyMethodCodeFix.cs # CA1024 fix provider
│ ├── StringComparisonAnalyzer.cs # CA1310 implementation
│ ├── StringComparisonCodeFix.cs # CA1310 fix provider
│ ├── LoggerMessageAnalyzer.cs # CA1848 implementation
│ ├── LoggerMessageCodeFix.cs # CA1848 fix provider
│ ├── MissingXmlDocsAnalyzer.cs # Documentation analyzer
│ └── MissingXmlDocsCodeFix.cs # Documentation fix provider
│
├── XmlFix.Analyzers.Tests/ # Comprehensive test suites
│ ├── PropertyMethodAnalyzerTests.cs
│ ├── PropertyMethodCodeFixTests.cs
│ ├── StringComparisonAnalyzerTests.cs
│ ├── StringComparisonCodeFixTests.cs
│ ├── LoggerMessageAnalyzerTests.cs
│ ├── LoggerMessageCodeFixTests.cs
│ └── ComprehensiveCodeFixTests.cs
│
└── .github/workflows/ # CI/CD configuration
└── build-and-sign.yml # Automated build pipeline
- Framework: .NET Standard 2.0
- Language: C# 12.0
- Roslyn: Microsoft.CodeAnalysis 4.8.0
- Testing: xUnit, Microsoft.CodeAnalysis.Testing
- CI/CD: GitHub Actions
- Overall: 93.97% (187/199 tests passing)
- PropertyMethod: 100% (33/33 tests)
- StringComparison Analyzer: 94.1% (16/17 tests)
- StringComparison CodeFix: 76.9% (10/13 tests)
- LoggerMessage: 42.9% (9/21 tests)
- ComprehensiveCodeFix: 93.75% (15/16 tests)
# Run all tests
dotnet test
# Run with coverage
dotnet test --collect:"XPlat Code Coverage"
# Run specific test category
dotnet test --filter "FullyQualifiedName~PropertyMethod"
# Run with detailed output
dotnet test --verbosity detailed- .NET SDK 8.0 or later
- Visual Studio 2022 or VS Code with C# Dev Kit
- Git for version control
# Clone repository
git clone https://github.com/mivertowski/XmlFix.git
cd XmlFix
# Restore dependencies
dotnet restore
# Build solution
dotnet build -c Release
# Run tests
dotnet test
# Create NuGet package
dotnet pack -c Release- Set
XmlFix.Sampleas startup project - Add breakpoints in analyzer code
- Press F5 to debug
- The analyzer will run on the sample project
We welcome contributions to improve XmlFix. Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/improvement) - Implement your changes with tests
- Ensure all tests pass (
dotnet test) - Commit with clear messages
- Push to your fork
- Submit a pull request
- Maintain test coverage above 90%
- Follow existing code style and conventions
- Update documentation for API changes
- Include tests for new functionality
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Security: See SECURITY.md for vulnerability reporting
- .NET Framework 4.6.1+
- .NET Core 2.0+
- .NET 5.0+
- Visual Studio 2019+
- VS Code with C# extension
- JetBrains Rider 2020.1+
XmlFix is licensed under the MIT License. See LICENSE for details.
Copyright © 2025 Michael Ivertowski
This project leverages the power of Roslyn to help developers write better, more maintainable .NET code through automated analysis and intelligent fixes.