Update readme.
This commit is contained in:
parent
7b03c7a55e
commit
fe43ae821d
28
README.md
28
README.md
|
@ -2,7 +2,9 @@
|
||||||
![Nuget](https://img.shields.io/nuget/v/mapto?logo=nuget)
|
![Nuget](https://img.shields.io/nuget/v/mapto?logo=nuget)
|
||||||
![Publish Packages](https://github.com/mrtaikandi/MapTo/workflows/Publish%20Packages/badge.svg)
|
![Publish Packages](https://github.com/mrtaikandi/MapTo/workflows/Publish%20Packages/badge.svg)
|
||||||
|
|
||||||
An object to object mapping generator using using [Roslyn source generator](https://github.com/dotnet/roslyn/blob/master/docs/features/source-generators.md).
|
An object to object mapping generator using [Roslyn source generator](https://github.com/dotnet/roslyn/blob/master/docs/features/source-generators.md).
|
||||||
|
|
||||||
|
MapTo creates mappings during compile-time, which eliminates the need for using reflection like other libraries. This makes it super simple to use and way faster than other libraries.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
```
|
```
|
||||||
|
@ -10,22 +12,28 @@ dotnet add package MapTo --prerelease
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
MapTo creates mappings during compile-time. To indicate which objects it needs to generate the mappings for, simply declare the class as `partial` and annotate it with `MapFrom` attribute.
|
To generate the mappings, simply declare the destination class as `partial` and annotate it with `MapFrom` attribute.
|
||||||
|
|
||||||
```c#
|
```c#
|
||||||
[MapFrom(sourceType: typeof(App.Data.Models.User))]
|
using MapTo;
|
||||||
public partial class UserViewModel
|
|
||||||
{
|
|
||||||
public string FirstName { get; }
|
|
||||||
|
|
||||||
public string LastName { get; }
|
namespace App.ViewModels
|
||||||
|
{
|
||||||
|
[MapFrom(typeof(App.Data.Models.User))]
|
||||||
|
public partial class UserViewModel
|
||||||
|
{
|
||||||
|
public string FirstName { get; }
|
||||||
|
|
||||||
[IgnoreProperty]
|
public string LastName { get; }
|
||||||
public string FullName { get; set; }
|
|
||||||
|
[IgnoreProperty]
|
||||||
|
public string FullName { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
If `Data.Models.User` class is defined as follow:
|
## Generated Source
|
||||||
|
In the above example, if `App.Data.Models.User` class is defined as:
|
||||||
|
|
||||||
```c#
|
```c#
|
||||||
namespace App.Data.Models
|
namespace App.Data.Models
|
||||||
|
|
Loading…
Reference in New Issue