AutoMapperAnalyzer.Analyzers 1.0.1

There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AutoMapperAnalyzer.Analyzers" Version="1.0.1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AutoMapperAnalyzer.Analyzers" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="AutoMapperAnalyzer.Analyzers">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AutoMapperAnalyzer.Analyzers --version 1.0.1
                    
#r "nuget: AutoMapperAnalyzer.Analyzers, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AutoMapperAnalyzer.Analyzers@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AutoMapperAnalyzer.Analyzers&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=AutoMapperAnalyzer.Analyzers&version=1.0.1
                    
Install as a Cake Tool

AutoMapper Roslyn Analyzer

Build Status NuGet Coverage License: MIT

๐Ÿ” 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
// โœ… 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Ensure all tests pass
  5. Submit a pull request

๐Ÿ“š Documentation

๐Ÿ› Issues & Support

๐ŸŽฏ 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
  1. Sprint 1: Complete AM004-AM005 + Enhanced messaging
  2. Sprint 2: Code fix providers for AM001-AM003
  3. Sprint 3: Architecture refactoring + performance optimization
  4. 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>

There are no supported framework assets in this package.

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.