Simple Mapper in C#
During application development you may need to convert your Domain-Models/Business-Objects to DTO or vice-versa. The famous library for solving this issue is AutoMapper but some times you can use this simple class with this implementation :) https://gist.github.com/imranbaloch/19ef360b5e45603860ba
1 |
public
static
class
Mapper
|
2 |
{
|
3 |
public
static
T2 Map<T1, T2>(T1 t1)
|
4 |
{
|
5 |
var json =
JsonConvert.SerializeObject(t1);
|
6 |
return
JsonConvert.DeserializeObject<T2>(json);
|
7 |
}
|
8 |
}
|