using System.Collections.Generic;
public interface IYourEntity
public class YourCustomer : IYourEntity
public int Id { get; set; }
public string CustomerName { get; set; }
public class YourOrder : IYourEntity
public int Id { get; set; }
public string OrderName { get; set; }
public class YourProduct : IYourEntity
public int Id { get; set; }
public string ProductName { get; set; }
public interface IMyEntity
string EntityName { get; set; }
public class MyEntity : IMyEntity
public int Id { get; set; }
public string EntityName { get; set; }
public class MyProduct : IMyEntity
public int Id { get; set; }
public string EntityName { get; set; }
public DateTime CreatedOn { get; set; }
public static class Extensions
public static IMyEntity ToMyEntity(this IYourEntity target)
return new MyEntity { Id = target.Id, EntityName = "Fallback name" };
public static IMyEntity ToMyEntity(this YourOrder target)
return new MyEntity { Id = target.Id, EntityName = target.OrderName.ToUpper() };
public static IMyEntity ToMyEntity(this YourProduct target)
return new MyProduct { Id = target.Id * 100, EntityName = target.ProductName };
public static List<IMyEntity> ToMyEntities(this List<IYourEntity> target)
var myEntities = new List<IMyEntity>();
foreach (var yourEntity in target)
var myEntity = Extensions.ToMyEntity((dynamic)yourEntity);
myEntities.Add(myEntity);
public static void Main(string[] args)
var yourEntities = new List<IYourEntity>()
new YourCustomer() { Id = 1 },
new YourOrder() { Id = 2, OrderName = "Order-2"},
new YourProduct() { Id = 3, ProductName = "Product-3"}
var myEnties = yourEntities.ToMyEntities();
myEnties.ForEach(o => Console.WriteLine("{0} - {1} ({2})",
o.Id, o.EntityName, o.GetType().Name