I, am trying to implement a generic method to convert one object to another object in c#.
Here is the some code I tried
public interface IDTOMapper<TSource, TDestination>
{
TDestination Convert(TSource source_object);
}
public class DtoMapper<TSource, TDestination> : IDTOMapper<TSource, TDestination>
{
public TDestination Convert(TSource source_object)
{
// How to write the code to convert one class object to another
}
}
The code which I used inside the convert method has lots of errors.Can anyone let me know how to implement with any class type objects. Some example I found has specific class object conversion.
When I google I found there is auto-mapper library I, don't want to use auto-mapper library. Just want to write custom generic method
Some of the reference
Best Practices for mapping one object to another
Generic method to map objects of different types
https://www.codeproject.com/Tips/781202/Csharp-Custom-Mapper