SmartMapValidator 1.2.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package SmartMapValidator --version 1.2.2
                    
NuGet\Install-Package SmartMapValidator -Version 1.2.2
                    
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="SmartMapValidator" Version="1.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SmartMapValidator" Version="1.2.2" />
                    
Directory.Packages.props
<PackageReference Include="SmartMapValidator" />
                    
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 SmartMapValidator --version 1.2.2
                    
#r "nuget: SmartMapValidator, 1.2.2"
                    
#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 SmartMapValidator@1.2.2
                    
#: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=SmartMapValidator&version=1.2.2
                    
Install as a Cake Addin
#tool nuget:?package=SmartMapValidator&version=1.2.2
                    
Install as a Cake Tool

SmartMapValidator

๐Ÿ”ง SmartMapValidator is a lightweight, attribute-based object mapping and validation library for C#. It helps you map DTOs to entities and validate properties using simple custom attributes.


๐Ÿš€ Features

  • โœ… Custom mapping with [MapTo] attribute
  • ๐Ÿšซ Skip mapping with [MapIgnore] attribute
  • ๐Ÿ“‹ Built-in validation support with [Required] and [Range] attributes
  • ๐Ÿงฉ Modular and extensible architecture

๐Ÿ“ฆ Installation

You can use it locally as a class library or package it as a NuGet package.

๐Ÿ”น Add project reference manually:

dotnet add reference ../SmartMapValidator/SmartMapValidator.csproj

๐Ÿงช Usage Example

Define a DTO and Entity:

public class UserDto
{
    [Required]
    public string Name { get; set; }

    [MapTo("UserAge")]
    [Range(18, 99)]
    public int Age { get; set; }

    [MapIgnore]
    public string Secret { get; set; }
}

public class UserEntity
{
    public string Name { get; set; }
    public int UserAge { get; set; }
}

Mapping:

var dto = new UserDto
{
    Name = "Aysel",
    Age = 25,
    Secret = "Hidden"
};

var entity = SmartMap.Map<UserDto, UserEntity>(dto);

// entity.Name -> "Aysel"
// entity.UserAge -> 25

Validation:

var invalidDto = new UserDto
{
    Name = "",
    Age = 10
};

var result = SmartMap.Validate(invalidDto);

if (!result.IsValid)
{
    Console.WriteLine(result.ToString());
    // Output:
    // Name field cannot be empty.
    // Age must be between 18 and 99.
}

๐Ÿงฑ Project Structure

SmartMapValidator/
โ”œโ”€โ”€ Attributes/
โ”‚   โ”œโ”€โ”€ MapToAttribute.cs
โ”‚   โ”œโ”€โ”€ MapIgnoreAttribute.cs
โ”œโ”€โ”€ Core/
โ”‚   โ”œโ”€โ”€ Mapper.cs
โ”‚   โ”œโ”€โ”€ Validator.cs
โ”‚   โ”œโ”€โ”€ ValidationResult.cs
โ”œโ”€โ”€ Interfaces/
โ”‚   โ”œโ”€โ”€ IMapDto.cs
โ”œโ”€โ”€ SmartMap.cs
โ”œโ”€โ”€ SmartMapValidator.csproj

๐Ÿ› ๏ธ Planned Features

  • [Regex] and [StringLength] validation attributes
  • Nested object mapping support
  • Optional AutoMapper integration

๐Ÿ“„ License

This project is open-source and licensed under the MIT License.


โœจ Author

Created by Rashad Aghayev
Contributions, pull requests, and suggestions are welcome! ๐Ÿ˜Š

๐Ÿ“ซ Contact

If you have any questions or suggestions, feel free to contact me at:
๐Ÿ“ง rashadaghayev85@gmail.com
๐Ÿ“ฑ +994 70 818 17 00

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2.3 253 4/8/2025
1.2.2 212 4/8/2025
1.2.0 219 4/7/2025
1.1.0 206 4/7/2025
1.0.0 224 4/7/2025