AutoMapperAnalyzer.Analyzers
1.0.1
See the version list below for details.
dotnet add package AutoMapperAnalyzer.Analyzers --version 1.0.1
NuGet\Install-Package AutoMapperAnalyzer.Analyzers -Version 1.0.1
<PackageReference Include="AutoMapperAnalyzer.Analyzers" Version="1.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="AutoMapperAnalyzer.Analyzers" Version="1.0.1" />
<PackageReference Include="AutoMapperAnalyzer.Analyzers"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add AutoMapperAnalyzer.Analyzers --version 1.0.1
#r "nuget: AutoMapperAnalyzer.Analyzers, 1.0.1"
#:package AutoMapperAnalyzer.Analyzers@1.0.1
#addin nuget:?package=AutoMapperAnalyzer.Analyzers&version=1.0.1
#tool nuget:?package=AutoMapperAnalyzer.Analyzers&version=1.0.1
AutoMapper Roslyn Analyzer
๐ Roslyn analyzer that detects AutoMapper configuration issues at compile-time to prevent runtime exceptions and data loss.
๐ Features
๐ก๏ธ Type Safety Validation
- AM001: Property type mismatch detection
- AM002: Nullable to non-nullable assignment warnings
- AM003: Collection type incompatibility errors
๐ Missing Property Detection
- AM010: Source properties not mapped to destination (data loss prevention)
- AM011: Required destination properties without source mapping
- AM012: Case sensitivity mismatches between properties
โ๏ธ Configuration Validation
- AM040: Missing AutoMapper profile registration
- AM041: Conflicting mapping rules for the same property
- AM042: Properties both ignored and explicitly mapped
โก Performance & Best Practices
- AM050: Static mapper usage detection (recommend dependency injection)
- AM051: Repeated mapping configuration warnings
- AM052: Missing null propagation in mapping chains
๐ฆ Installation
Package Manager
Install-Package AutoMapperAnalyzer.Analyzers
Install-Package AutoMapperAnalyzer.CodeFixes
.NET CLI
dotnet add package AutoMapperAnalyzer.Analyzers
dotnet add package AutoMapperAnalyzer.CodeFixes
PackageReference
<PackageReference Include="AutoMapperAnalyzer.Analyzers" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="AutoMapperAnalyzer.CodeFixes" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
๐ฏ Quick Start
Once installed, the analyzer automatically detects issues in your AutoMapper configurations:
โ Problems Detected
// AM001: Property type mismatch
class Source { public string Age { get; set; } }
class Dest { public int Age { get; set; } }
cfg.CreateMap<Source, Dest>(); // โ Warning: string -> int without converter
// AM002: Nullable to non-nullable
class Source { public string? Name { get; set; } }
class Dest { public string Name { get; set; } }
cfg.CreateMap<Source, Dest>(); // โ Warning: Potential NullReferenceException
// AM010: Missing destination property (data loss)
class Source { public string ImportantData { get; set; } }
class Dest { /* Missing ImportantData property */ }
cfg.CreateMap<Source, Dest>(); // โ Warning: Data loss potential
โ Recommended Solutions
// โ
Explicit type conversion
cfg.CreateMap<Source, Dest>()
.ForMember(dest => dest.Age, opt => opt.MapFrom(src =>
int.TryParse(src.Age, out var age) ? age : 0));
// โ
Null safety handling
cfg.CreateMap<Source, Dest>()
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name ?? "Unknown"));
// โ
Explicit data handling
cfg.CreateMap<Source, Dest>()
.ForMember(dest => dest.Summary, opt => opt.MapFrom(src =>
$"Name: {src.Name}, Data: {src.ImportantData}"));
๐ง Configuration
Severity Levels
Configure diagnostic severity in your .editorconfig
:
# Error level diagnostics (build failures)
dotnet_diagnostic.AM001.severity = error # Type mismatches
dotnet_diagnostic.AM003.severity = error # Collection incompatibility
dotnet_diagnostic.AM011.severity = error # Missing required properties
# Warning level diagnostics
dotnet_diagnostic.AM002.severity = warning # Nullable issues
dotnet_diagnostic.AM010.severity = warning # Data loss potential
dotnet_diagnostic.AM040.severity = warning # Missing profiles
# Information level diagnostics
dotnet_diagnostic.AM012.severity = suggestion # Case sensitivity
dotnet_diagnostic.AM050.severity = suggestion # Performance hints
Suppressing Diagnostics
// Suppress specific diagnostics with justification
#pragma warning disable AM001 // Justification: Custom converter handles this
cfg.CreateMap<Source, Dest>();
#pragma warning restore AM001
// Suppress via attributes
[SuppressMessage("AutoMapper", "AM010:Missing destination property",
Justification = "Data intentionally excluded for security")]
public void ConfigureMapping() { }
๐ Supported Scenarios
Scenario | Analyzer Support | Code Fix Support |
---|---|---|
Type Safety | โ All cases | โ Common patterns |
Missing Properties | โ All cases | โ Auto-mapping |
Configuration Issues | โ All cases | โ Profile registration |
Performance | โ All cases | โ DI patterns |
Custom Converters | โ Detection | ๐ง Planned |
EF Integration | ๐ง Planned | ๐ง Planned |
๐๏ธ Building from Source
# Clone repository
git clone https://github.com/georgepwall1991/automapper-analyser.git
cd automapper-analyser
# Restore dependencies
dotnet restore
# Build solution
dotnet build --configuration Release
# Run tests
dotnet test --configuration Release
# Create packages
dotnet pack --configuration Release --output ./packages
๐งช Testing
# Run all tests
dotnet test
# Run with coverage
dotnet test --collect:"XPlat Code Coverage"
# Run sample scenarios
dotnet run --project samples/AutoMapperAnalyzer.Samples
๐ Contributing
We welcome contributions! Please read our Contributing Guidelines for details.
Development Requirements
- .NET 9.0 SDK
- Visual Studio 2022 or JetBrains Rider
- Basic knowledge of Roslyn analyzers
Quick Contribution Steps
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Ensure all tests pass
- Submit a pull request
๐ Documentation
- Architecture Overview - System design and components
- Diagnostic Rules - Complete list of analyzer rules
- CI/CD Pipeline - Build and deployment process
- Sample Code - Example scenarios
๐ Issues & Support
- ๐ Bug Reports: GitHub Issues
- ๐ก Feature Requests: GitHub Discussions
- ๐ Documentation: Wiki
- ๐ฌ Community: AutoMapper Discord
๐ฏ Next Steps
Kick-off Workshop to Review Findings & Align on Remediation Priorities
Now that we have successfully implemented our core analyzers (AM001, AM002, AM003) with 100% test coverage, it's time to strategically plan our next development phase.
Workshop Objectives:
- Review current analyzer capabilities and performance
- Identify high-impact areas for improvement
- Align team on technical debt vs. new feature priorities
- Establish clear success metrics for next phase
Build a Prioritized Backlog: Quick Wins (Linting, Logging), Strategic Refactors (Architecture, Process)
๐ Quick Wins (1-2 Sprint Capacity)
Linting & Code Quality:
- AM004: Missing Property Diagnostics - Detect data loss scenarios
- AM005: Case Sensitivity Mapping Issues
- Enhanced diagnostic messages with actionable suggestions
- EditorConfig integration for severity customization
Logging & Observability:
- Analyzer performance metrics and telemetry
- Debug logging for complex mapping scenarios
- Test coverage reporting integration
- Build-time diagnostic statistics
๐๏ธ Strategic Refactors (3-5 Sprint Capacity)
Architecture Improvements:
- Shared type compatibility engine across analyzers
- Plugin architecture for custom rule extensions
- Improved semantic model caching for performance
- Rule configuration system (severity, scope, exclusions)
Process Enhancements:
- Code fix providers for automatic remediation
- IDE integration improvements (Visual Studio, Rider)
- CI/CD pipeline optimizations
- Documentation automation and examples
๐ฏ Success Metrics
Technical Excellence:
- Maintain 95%+ test coverage across all analyzers
- Sub-100ms analysis time for typical project files
- Zero false positives in common AutoMapper patterns
- 90%+ developer satisfaction with diagnostic accuracy
Developer Experience:
- One-click installation and configuration
- Actionable diagnostics with clear remediation steps
- Seamless IDE integration with immediate feedback
- Comprehensive documentation and examples
๐ Recommended Sprint Planning
- Sprint 1: Complete AM004-AM005 + Enhanced messaging
- Sprint 2: Code fix providers for AM001-AM003
- Sprint 3: Architecture refactoring + performance optimization
- Sprint 4: IDE integration + developer experience improvements
๐ Roadmap
Phase 1: Foundation โ
- Core analyzer infrastructure
- Type safety validation (AM001, AM002, AM003)
- Comprehensive test framework
- CI/CD pipeline with quality gates
Phase 2: Advanced Features ๐ง
- Missing property detection (AM004, AM005)
- Custom converter validation
- Complex nested object mapping
- Performance optimization hints
- Code fix providers
Phase 3: Ecosystem Integration ๐
- Visual Studio extension
- JetBrains Rider plugin
- Azure DevOps integration
- SonarQube rules
๐ Recognition
This project is part of the AutoMapper ecosystem, helping developers write safer and more maintainable mapping code.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ค Acknowledgments
- George Wall - Project maintainer and lead developer
- Jimmy Bogard - Creator of AutoMapper
- AutoMapper Contributors - For the excellent mapping library
- Roslyn Team - For the powerful analyzer framework
- Community - For feedback and contributions
<div align="center">
Documentation โข Samples โข Contributing โข License
Made with โค๏ธ by the AutoMapper community
</div>
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.5.611.1239 | 287 | 6/11/2025 |
1.5.611.1228 | 276 | 6/11/2025 |
1.5.611.1119 | 280 | 6/11/2025 |
1.5.606.1627 | 91 | 6/6/2025 |
1.5.606.1343 | 98 | 6/6/2025 |
1.5.606.1341 | 95 | 6/6/2025 |
1.5.606.1035 | 109 | 6/6/2025 |
1.5.606.946 | 117 | 6/6/2025 |
1.5.606.940 | 106 | 6/6/2025 |
1.0.4 | 108 | 6/6/2025 |
1.0.3 | 139 | 6/5/2025 |
1.0.2 | 140 | 6/5/2025 |
1.0.1 | 134 | 6/5/2025 |
1.0.0 | 136 | 6/5/2025 |
Initial release of AutoMapper Roslyn Analyzer with support for type safety, missing property detection, and configuration validation.