A simple and lightweight attribute based object mapping library for .NET
$ dotnet add package StarFuryDev.ObjectMapperA simple and lightweighta attribute based object mapping library for .NET, built as a hobby project to make object-to-object mapping easier.
I created this library as a personal learning project and wanted to share it with the community. While there are other great mapping libraries out there, I built this to:
Feel free to use it or just peek at the code!
Install via NuGet Package Manager:
dotnet add package StarFuryDev.ObjectMapper
Or via Package Manager Console:
Install-Package StarFuryDev.ObjectMapper
using StarFuryDev.ObjectMapper;
// Source data
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
}
// Destination
[MapFrom(nameof(Person))]
public class Profile
{
// default mapping - source property name = destination property name
public string FirstName { get; set; }
// Map from using a custom converter
[MapFromUsing(typeof(CustomConverters), nameof(CustomConverters.ConvertToFullName))]
public string FullName { get; set; }
// Map from using a different property
[MapFrom(nameof(Source.Age))]
public int MyAge { get; set; }
// Ignore when mapping
[MapIgnore]
prop string Address { get; set; }
}
public static class CustomConverters
{
public static string ConvertToFullName(string firstName, string lastName)
{
return $"{firstName} {lastname}";
}
}
// Simple mapping
var person = new Person { FirstName = "John", LastName = "Smith" Age = 30 };
var profile = Mapper.Map<Person, Profile>(person);
Since this is a hobby project, there are some limitations:
This is a hobby project, but contributions are welcome! If you find a bug or have an idea:
No contribution is too small - typo fixes, documentation improvements, and feature suggestions are all appreciated!
# Clone the repository
git clone https://github.com/starfury-dev/ObjectMapper.git
# Restore dependencies
dotnet restore
# Build
dotnet build
# Run tests
dotnet test
⭐ If you find this project useful, consider giving it a star on GitHub!