AutoMapperAnalyzer.Analyzers 1.5.611.1239

There is a newer version of this package available.
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
                    
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.5.611.1239">
  <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.5.611.1239" />
                    
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.5.611.1239
                    
#r "nuget: AutoMapperAnalyzer.Analyzers, 1.5.611.1239"
                    
#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.5.611.1239
                    
#: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.5.611.1239
                    
Install as a Cake Addin
#tool nuget:?package=AutoMapperAnalyzer.Analyzers&version=1.5.611.1239
                    
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.

๐Ÿš€ 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> to HashSet<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
// โœ… 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

  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

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.
  • Performance Analyzers:
    • AM050: Detect static Mapper.Map usage.
    • AM052: Find mapping chains without null propagation.
  • 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.

There are no supported framework assets in this package.

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.