Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Program
- {
- public class Program
- {
- public static void Main()
- {
- var lion = new Lion { Name = "Simba" };
- var tiger = lion.CreateMap<Tiger, Lion>(Cast);
- Console.WriteLine(tiger.FullName);
- }
- public static void Cast(Tiger dest, Lion src)
- {
- dest.FullName = src.Name;
- }
- }
- public class Lion
- {
- public string Name { get; set; }
- }
- public class Tiger
- {
- public string FullName { get; set; }
- }
- }
- namespace System {
- public static class ObjectExtensions {
- public static TDestination CreateMap<TDestination, TSource>(this TSource src, Action<TDestination, TSource> action) where TDestination : new()
- {
- var result = new TDestination();
- action(result, src);
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement