SmartMapValidator 1.2.3

dotnet add package SmartMapValidator --version 1.2.3
                    
NuGet\Install-Package SmartMapValidator -Version 1.2.3
                    
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.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SmartMapValidator" Version="1.2.3" />
                    
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.3
                    
#r "nuget: SmartMapValidator, 1.2.3"
                    
#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.3
                    
#: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.3
                    
Install as a Cake Addin
#tool nuget:?package=SmartMapValidator&version=1.2.3
                    
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 object properties using simple custom attributes.


๐Ÿš€ Features

  • โœ… Attribute-based mapping with [MapTo]
  • ๐Ÿšซ Ignore properties with [MapIgnore]
  • ๐Ÿ“‹ Built-in validation attributes:
    • [Required] โ€” ensures field is not null or empty
    • [Range(min, max)] โ€” numeric range validation
    • [Regex(pattern)] โ€” validates against a regular expression
    • [MinLength(length)] / [MaxLength(length)] โ€” string length limits
  • ๐Ÿ”„ Nullable type support (e.g., int?, DateTime?)
  • ๐Ÿงฉ Modular, extensible, clean architecture

๐Ÿ“ฆ Installation

You can use the library locally as a class library, or publish it to NuGet.

๐Ÿ”น Add as a project reference

dotnet add reference ../SmartMapValidator/SmartMapValidator.csproj

๐Ÿงช Usage Example

DTO and Entity Definitions

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

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

    [Regex(@"^\S+@\S+\.\S+$")]
    public string Email { get; set; }

    [MinLength(6)]
    [MaxLength(20)]
    public string Username { get; set; }

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

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

Mapping

var dto = new UserDto
{
    Name = "Rashad",
    Age = 28,
    Email = "rashad@example.com",
    Username = "rashad_28",
    Secret = "TopSecret"
};

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

// entity.Name -> "Rashad"
// entity.UserAge -> 28
// entity.Email -> "rashad@example.com"

Validation

var invalidDto = new UserDto
{
    Name = "",
    Age = 15,
    Email = "invalid_email",
    Username = "abc"
};

var result = SmartMap.Validate(invalidDto);

if (!result.IsValid)
{
    Console.WriteLine(result.ToString());
    // Output:
    // Name is required.
    // Age must be between 18 and 99.
    // Email format is invalid.
    // Username must be at least 6 characters.
}

๐Ÿ› ๏ธ Planned Features

  • Nested object mapping
  • Collection support (e.g., List<T>)
  • AutoMapper integration

๐Ÿ“„ License

Licensed under the MIT License.


โœจ Author

Created with by Rashad Aghayev
Pull requests and contributions are always welcome!

๐Ÿ“ง 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 190 4/8/2025
1.2.2 160 4/8/2025
1.2.0 170 4/7/2025
1.1.0 164 4/7/2025
1.0.0 171 4/7/2025