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" />
<PackageReference Include="SmartMapValidator" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=SmartMapValidator&version=1.2.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | Versions 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.
-
net8.0
- System.ComponentModel.Annotations (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.