AutoMapperAnalyzer.Analyzers
1.5.611.1239
See the version list below for details.
dotnet add package AutoMapperAnalyzer.Analyzers --version 1.5.611.1239
NuGet\Install-Package AutoMapperAnalyzer.Analyzers -Version 1.5.611.1239
<PackageReference Include="AutoMapperAnalyzer.Analyzers" Version="1.5.611.1239"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="AutoMapperAnalyzer.Analyzers" Version="1.5.611.1239" />
<PackageReference Include="AutoMapperAnalyzer.Analyzers"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add AutoMapperAnalyzer.Analyzers --version 1.5.611.1239
#r "nuget: AutoMapperAnalyzer.Analyzers, 1.5.611.1239"
#:package AutoMapperAnalyzer.Analyzers@1.5.611.1239
#addin nuget:?package=AutoMapperAnalyzer.Analyzers&version=1.5.611.1239
#tool nuget:?package=AutoMapperAnalyzer.Analyzers&version=1.5.611.1239
AutoMapper Roslyn Analyzer
๐ Roslyn analyzer that detects AutoMapper configuration issues at compile-time to prevent runtime exceptions and data loss.
๐ Implemented Analyzer Rules
This analyzer currently implements the following diagnostic rules to help you catch AutoMapper issues at compile time.
๐ก๏ธ Type Safety Diagnostics
- AM001: Property Type Mismatch: Detects when source and destination properties have incompatible types without an explicit type converter.
- AM002: Nullable to Non-Nullable Assignment: Warns when a nullable source property is mapped to a non-nullable destination property without proper null handling.
- AM003: Collection Type Incompatibility: Finds incompatible collection types between source and destination (e.g.,
List<string>
toHashSet<int>
).
๐ Missing Property and Mapping Diagnostics
- AM010: Missing Destination Property: Warns about source properties that do not have a corresponding property in
the destination type, preventing potential data loss. (Implemented as
AM004
in code) - AM011: Unmapped Required Property: Generates an error when a
required
property in the destination type is not mapped, which would cause a runtime exception. - AM012: Case Sensitivity Mismatch: Detects when source and destination property names differ only by case, which
can lead to unexpected mapping behavior. (Implemented as
AM005
in code)
๐งฉ Collection and Complex Type Diagnostics
- AM020: Nested Object Mapping Issues: Detects when nested complex objects are used without a corresponding
CreateMap
call for them.
๐ Future Rules
Support for more diagnostic rules is planned, including:
- Custom conversion validation
- Configuration issues (e.g., missing profiles)
- Performance and best practice recommendations
- Entity Framework-specific mapping problems
๐ฆ Installation
๐ฏ Compatibility
The AutoMapper Analyzer is fully compatible with:
Framework | Version | Status | Notes |
---|---|---|---|
.NET Framework | 4.8+ | โ Fully Supported | Requires AutoMapper 10.x+ |
.NET Core | 3.1+ | โ Fully Supported | LTS version recommended |
.NET | 5.0+ | โ Fully Supported | Latest features supported |
.NET Standard | 2.0+ | โ Fully Supported | Analyzer targets netstandard2.0 |
The analyzer itself targets .NET Standard 2.0, ensuring maximum compatibility across all modern .NET platforms.
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>
๐ง Framework-Specific Notes
.NET Framework 4.8
- Use AutoMapper 10.x series for maximum compatibility
- Nullable reference types supported with C# 8.0+
- Full analyzer functionality available
.NET Core 3.1
- LTS version with full support
- Recommended for production applications
- All analyzer features work correctly
.NET 5.0+
- Latest analyzer features supported
- Best performance and compatibility
- Recommended for new projects
๐ฏ 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 Diagnostics
Rule ID | Description | Analyzer Status | Code Fix Status |
---|---|---|---|
AM001 | Property Type Mismatch | โ Implemented | ๐ง Planned |
AM002 | Nullable to Non-nullable | โ Implemented | ๐ง Planned |
AM003 | Collection Type Incompatibility | โ Implemented | ๐ง Planned |
AM010 | Missing Destination Property | โ Implemented | ๐ง Planned |
AM011 | Unmapped Required Property | โ Implemented | ๐ง Planned |
AM012 | Case Sensitivity Mismatch | โ Implemented | ๐ง Planned |
AM020 | Nested Object Mapping Issues | โ Implemented | ๐ง Planned |
AM021+ | Other Complex/Collection Rules | ๐ง Planned | ๐ง Planned |
AM030+ | Custom Conversion Rules | ๐ง Planned | ๐ง Planned |
AM040+ | Configuration Rules | ๐ง Planned | ๐ง Planned |
AM050+ | Performance Rules | ๐ง Planned | ๐ง Planned |
AM060+ | EF Integration Rules | ๐ง 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
Review and Prioritization
With a solid foundation of type safety, property mapping, and complex type analyzers in place, the next phase of development will focus on expanding coverage to configuration, performance, and other advanced scenarios.
Prioritized Backlog
The following is a high-level view of planned features:
๐ Immediate Priorities
- Code Fixes: Implement code fix providers for existing analyzers (e.g., suggesting explicit conversions for
AM001
). - Enhanced Diagnostics: Improve diagnostic messages with more context and actionable suggestions.
- EditorConfig Integration: Ensure all analyzer severities can be customized via
.editorconfig
.
๐๏ธ Future Milestones
- Configuration Analyzers:
- AM040: Missing
Profile
registration. - AM041: Conflicting mapping rules.
- AM040: Missing
- Performance Analyzers:
- AM050: Detect static
Mapper.Map
usage. - AM052: Find mapping chains without null propagation.
- AM050: Detect static
- Logging & Telemetry:
- Add performance metrics for analyzer execution.
- Integrate build-time diagnostic statistics.
- Architectural Scalability: Refactor core analyzer components for better extensibility.
- Performance Optimization: Reduce memory footprint and improve analysis speed.
- CI/CD Pipeline Enhancements: Add automated release notes and documentation updates.
- Test Suite Modernization: Migrate to latest testing frameworks and patterns.
- Code Fix Infrastructure: Build robust infrastructure for suggesting complex code changes.
๐ License
This project is licensed under the MIT License.
Learn more about Target Frameworks and .NET Standard.
This package has 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.722.1040 | 11 | 7/22/2025 |
1.5.722.25 | 15 | 7/21/2025 |
1.5.611.1239 | 288 | 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.