BlazMapper 0.0.5
dotnet add package BlazMapper --version 0.0.5
NuGet\Install-Package BlazMapper -Version 0.0.5
<PackageReference Include="BlazMapper" Version="0.0.5" />
<PackageVersion Include="BlazMapper" Version="0.0.5" />
<PackageReference Include="BlazMapper" />
paket add BlazMapper --version 0.0.5
#r "nuget: BlazMapper, 0.0.5"
#:package BlazMapper@0.0.5
#addin nuget:?package=BlazMapper&version=0.0.5
#tool nuget:?package=BlazMapper&version=0.0.5
BlazMapper
Description
Simple and efficient object mapper for .NET
Descrição
Mapeador de objetos simples e eficiente para .NET*
BlazMapper
(Português) Clique no seu idioma preferido abaixo. O triângulo (acima do idioma) exibe/esconde o texto.
(English) Click on your preferred language below: The triangle (above the language) shows/hides the text.
<details open> <summary><h2 id="english">🇺🇸 English</h2></summary>
A simple and efficient library for object mapping in .NET, supporting both mutable and immutable objects with parameterized constructors.
🚀 Features
- Automatic Mapping: Maps properties automatically based on names (case-insensitive)
- Immutable Objects: Full support for objects with parameterized constructors
- Mutable Objects: Support for objects with settable properties
- Implicit Conversions: Detects and applies implicit conversions automatically
- Recursive Mapping: Maps complex nested objects
- High Performance: Uses reflection in an optimized way
📦 Installation
dotnet add package BlazMapper
🔧 How to Use
Basic Usage
using BlazMapper;
// For mutable objects
var source = new { Name = "John", Age = 30 };
var destination = source.MapTo<object, Person>();
// For immutable objects
public record PersonRecord(string Name, int Age);
var record = source.MapTo<object, PersonRecord>();
Practical Examples
Simple Class Mapping
public class SourcePerson
{
public string Name { get; set; }
public int Age { get; set; }
public string Email { get; set; }
}
public class DestinationPerson
{
public string Name { get; set; }
public int Age { get; set; }
public string Email { get; set; }
}
var source = new SourcePerson
{
Name = "Mary",
Age = 25,
Email = "mary@email.com"
};
var destination = source.MapTo<SourcePerson, DestinationPerson>();
Mapping with Records (Immutable Objects)
public record SourceRecord(string FirstName, string LastName, int Age);
public record DestinationRecord(string FirstName, string LastName, int Age);
var source = new SourceRecord("John", "Smith", 30);
var destination = source.MapTo<SourceRecord, DestinationRecord>();
Complex Object Mapping
public class Address
{
public string Street { get; set; }
public string City { get; set; }
}
public class Person
{
public string Name { get; set; }
public Address Address { get; set; }
}
// BlazMapper automatically maps nested objects
var source = new Person
{
Name = "Peter",
Address = new Address { Street = "Main St", City = "New York" }
};
var destination = source.MapTo<Person, PersonDto>();
Mapping with Value Objects
public class CompleteName : AValueObject
{
public CompleteName(string fullName)
{
this.FullName = fullName;
var names = fullName.Split(' ');
if (names.Length >= 2)
{
this.FirstName = names[0];
this.LastName = names[names.Length - 1];
}
else
{
this.FirstName = fullName;
this.LastName = string.Empty;
}
GetValidationExpression();
}
public CompleteName(string firstName, string lastName)
{
this.FirstName = firstName;
this.LastName = lastName;
this.FullName = $"{firstName} {lastName}";
GetValidationExpression();
}
public string FullName { get; private set; } = string.Empty;
public string FirstName { get; private set; } = string.Empty;
public string LastName { get; private set; } = string.Empty;
public override bool GetValidationExpression()
{
return this.IsValid = this.IsValidName(FullName);
}
public override string ToString()
{
return this.FullName;
}
protected override IEnumerable<object> GetEqualityComponents()
{
yield return this.FullName;
}
private bool IsValidName(string fullName)
{
return !string.IsNullOrWhiteSpace(fullName) && fullName.Contains(' ');
}
public static implicit operator string(CompleteName name) => name.FullName;
public static implicit operator CompleteName(string fullname) => new CompleteName(fullname);
}
public class PersonWithCompleteName
{
public int Id { get; set; }
public CompleteName Name { get; set; } = new("Unknown Person");
public int Age { get; set; }
public string Department { get; set; } = string.Empty;
}
var source = new PersonWithStringName
{
Id = 1,
Name = "Ana Costa",
Age = 28
};
// BlazMapper automatically maps value objects
var destination = source.MapTo<PersonWithStringName, PersonWithCompleteName>();
🔍 How It Works
BlazMapper automatically analyzes source and destination types:
- For objects with parameterized constructors: Maps properties to constructor parameters
- For mutable objects: Creates instance and sets properties
- Conversions: Applies implicit conversions when necessary
- Recursive mapping: Maps complex objects automatically
⚡ Performance
- Uses optimized reflection
- Internal cache for better performance on repeated mappings
- Support for nested objects without performance loss
🤝 Contributing
Contributions are welcome! Feel free to:
- Report bugs
- Suggest improvements
- Submit pull requests
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 Links
</details>
<details> <summary><h2 id="portugues">🇧🇷 Português</h2></summary>
Uma biblioteca simples e eficiente para mapeamento de objetos em .NET, suportando tanto objetos mutáveis quanto imutáveis com construtor parametrizado.
🚀 Características
- Mapeamento Automático: Mapeia propriedades automaticamente baseado nos nomes (case-insensitive)
- Objetos Imutáveis: Suporte completo para objetos com construtores parametrizados
- Objetos Mutáveis: Suporte para objetos com propriedades setáveis
- Conversões Implícitas: Detecta e aplica conversões implícitas automaticamente
- Mapeamento Recursivo: Mapeia objetos complexos aninhados
- Alta Performance: Usa reflection de forma otimizada
📦 Instalação
dotnet add package BlazMapper
🔧 Como Usar
Uso Básico
using BlazMapper;
// Para objetos mutáveis
var source = new { Name = "João", Age = 30 };
var destination = source.MapTo<object, Person>();
// Para objetos imutáveis
public record PersonRecord(string Name, int Age);
var record = source.MapTo<object, PersonRecord>();
Exemplos Práticos
Mapeamento de Classes Simples
public class SourcePerson
{
public string Name { get; set; }
public int Age { get; set; }
public string Email { get; set; }
}
public class DestinationPerson
{
public string Name { get; set; }
public int Age { get; set; }
public string Email { get; set; }
}
var source = new SourcePerson
{
Name = "Maria",
Age = 25,
Email = "maria@email.com"
};
var destination = source.MapTo<SourcePerson, DestinationPerson>();
Mapeamento com Records (Objetos Imutáveis)
public record SourceRecord(string FirstName, string LastName, int Age);
public record DestinationRecord(string FirstName, string LastName, int Age);
var source = new SourceRecord("João", "Silva", 30);
var destination = source.MapTo<SourceRecord, DestinationRecord>();
Mapeamento de Objetos Complexos
public class Address
{
public string Street { get; set; }
public string City { get; set; }
}
public class Person
{
public string Name { get; set; }
public Address Address { get; set; }
}
// O BlazMapper mapeia automaticamente objetos aninhados
var source = new Person
{
Name = "Pedro",
Address = new Address { Street = "Rua A", City = "São Paulo" }
};
var destination = source.MapTo<Person, PersonDto>();
Mapeando para Value Objects
public class CompleteName : AValueObject
{
public CompleteName(string fullName)
{
this.FullName = fullName;
var names = fullName.Split(' ');
if (names.Length >= 2)
{
this.FirstName = names[0];
this.LastName = names[names.Length - 1];
}
else
{
this.FirstName = fullName;
this.LastName = string.Empty;
}
GetValidationExpression();
}
public CompleteName(string firstName, string lastName)
{
this.FirstName = firstName;
this.LastName = lastName;
this.FullName = $"{firstName} {lastName}";
GetValidationExpression();
}
public string FullName { get; private set; } = string.Empty;
public string FirstName { get; private set; } = string.Empty;
public string LastName { get; private set; } = string.Empty;
public override bool GetValidationExpression()
{
return this.IsValid = this.IsValidName(FullName);
}
public override string ToString()
{
return this.FullName;
}
protected override IEnumerable<object> GetEqualityComponents()
{
yield return this.FullName;
}
private bool IsValidName(string fullName)
{
return !string.IsNullOrWhiteSpace(fullName) && fullName.Contains(' ');
}
public static implicit operator string(CompleteName name) => name.FullName;
public static implicit operator CompleteName(string fullname) => new CompleteName(fullname);
}
public class PersonWithCompleteName
{
public int Id { get; set; }
public CompleteName Name { get; set; } = new("Unknown Person");
public int Age { get; set; }
public string Department { get; set; } = string.Empty;
}
var source = new PersonWithStringName
{
Id = 1,
Name = "Ana Costa",
Age = 28
};
// BlazMapper automatically maps value objects
var destination = source.MapTo<PersonWithStringName, PersonWithCompleteName>();
🔍 Como Funciona
O BlazMapper analisa automaticamente os tipos de origem e destino:
- Para objetos com construtores parametrizados: Mapeia propriedades para parâmetros do construtor
- Para objetos mutáveis: Cria instância e define propriedades
- Conversões: Aplica conversões implícitas quando necessário
- Mapeamento recursivo: Mapeia objetos complexos automaticamente
⚡ Performance
- Usa reflection otimizada
- Cache interno para melhor performance em mapeamentos repetidos
- Suporte para objetos aninhados sem perda de performance
🤝 Contribuindo
Contribuições são bem-vindas! Sinta-se à vontade para:
- Reportar bugs
- Sugerir melhorias
- Enviar pull requests
📄 Licença
Este projeto está licenciado sob a licença MIT - veja o arquivo LICENSE para detalhes.
🔗 Links
</details>
<p align="center"> <strong>Desenvolvido com ❤️ para a comunidade .NET<br> Developed with ❤️ for the .NET community</strong> </p>
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. |
-
net8.0
- 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.