Skip to content

Configuration Analyzers

quyvu edited this page Oct 14, 2026 · 3 revisions

FxMap Analyzers

Roslyn code analyzer that validates FxMap Expression syntax during compilation. Catch expression errors before runtime and prevent production failures.

Why Use Analyzers?

Compile-Time Safety

Catch syntax errors during development, not in production

IDE Integration

See errors highlighted in Visual Studio, VS Code, and Rider

Zero Runtime Cost

Validation happens at build time with no performance impact

Installation

Add the analyzer package to your project:

dotnet add package FxMap.Analyzers

Or via Project Reference

<ItemGroup>
  <ProjectReference Include="../path/to/FxMap.Analyzers/FxMap.Analyzers.csproj" />
</ItemGroup>

Diagnostic Rule: fxmap001

Expression Syntax Validation

Severity: ErrorCategory: Syntax

The analyzer validates six key aspects of FxMap expressions:

Balanced Delimiters

Ensures braces {} for projections and the parentheses () of function arguments, such as :where(condition), are properly matched

Valid: Orders:where(Status = 'Done') Invalid: Orders:where(Status = 'Done'

Property Navigation

Requires dots before projections and after filters and functions

Valid: Country.{Id} Invalid: Country{Id}

Function Validation

Checks function names against known FxMap functions

Valid: Name:upper Invalid: Name:invalid

Computed Expressions

Computed expressions in projections must include aliases

Valid: {FullName: (Name:upper)} Invalid: {(Name:upper)}

Removed Syntax (5.0)

Reports the indexer [...] and the filter Collection(condition), which were removed in 5.0, and names the function to use instead

Valid: Orders:where(Status = 'Done'):orderBy(Date):first Invalid: Orders(Status = 'Done')[0 asc Date]

Operators

Only allows valid operators: =, !=, >, <, >=, <=, contains, startswith, endswith

Valid: Status = 'Done' Invalid: Status == 'Done'

Valid Expression Examples

Country.Name

Simple property navigation

Country.{Id, Name}

Projection with dot notation

{Id, Name, Email}

Root projection

Orders:where(Status = 'Done').Items

Filter with navigation

Provinces:orderBy(Name):first.Name

Sort, pick the first item, then navigate

{Id, FullName: (Name:upper)}

Computed expression with alias

Invalid Expressions (Analyzer Catches)

Country{Id, Name}

Missing dot before projectionRule: Property Navigation

Orders:where(Status = 'Done')Items

Missing dot after filterRule: Property Navigation

{Id, (Name:upper)}

Computed expression without aliasRule: Computed Expressions

Name:invalid

Unknown functionRule: Function Validation

Orders:where(Status == 'Done')

Invalid operator (use = not ==)Rule: Operators

Orders(Status = 'Done')

The filter was removed in 5.0: use :where(...)Rule: Removed Syntax

Orders[0 asc Date]

The indexer was removed in 5.0: use :orderBy(...) with :first, :offset or :limitRule: Removed Syntax

How It Works

  1. 1

    Compilation Trigger

    Analyzer runs during compilation as part of the Roslyn compilation pipeline

  2. 2

    Configuration Inspection

    Finds your ProfileOf configurations and the expression strings passed to .For(), .Expression() and .Else()

  3. 3

    Expression Parsing

    Parses each expression using the full FxMap expression parser

  4. 4

    Error Reporting

    Reports syntax errors with position information in your IDE

Important Limitation

This is a syntax-only validator. The analyzer does NOT:

  • Verify property names exist in your entities
  • Validate navigation paths for your data model
  • Check data types or type compatibility
  • Validate semantic correctness

These checks occur at runtime when FxMap processes your expressions.


Source: https://fxmapper.net/docs/configuration/analyzers/ — the website is always the most up to date version.

Clone this wiki locally