using System.Collections;
using System.Collections.Generic;
public static void Main()
ObjectWithLists objSource = new ObjectWithLists();
objSource.List1 = new List<string> { "1", "2", "3" };
objSource.List2 = new List<ListItem>();
objSource.List2.Add(new ListItem() { Id = 4, Libelle = "test" });
ObjectWithLists objTarget = new ObjectWithLists();
CopierValeurs(objSource, objTarget);
Console.WriteLine(string.Concat("source : ", objSource));
Console.WriteLine(string.Concat("target : ", objTarget));
public static void CopierValeurs(object source, object cible)
if (source == null || cible == null)
var cibleProps = cible.GetType().GetProperties().Where(p => p.CanWrite).ToList();
var sourceProps = source.GetType().GetProperties().Where(p => p.CanRead).ToList();
Func<string, object> Get = (p) =>
sourceProps.First(x => x.Name == p).GetValue(source);
Action<string, object> Set = (p, val) =>
cibleProps.First(x => x.Name == p).SetValue(cible, val);
.Intersect(sourceProps.Select(t => t.Name))
public class ObjectWithLists
public string Prop1 {get;set;}
public List<string> List1 {get;set;}
public List<ListItem> List2 {get;set;}
public override string ToString()
return string.Concat( "List1:", string.Join(",", List1.Select(x => x).ToArray()),
"List2:", string.Join(",", List2.Select(x => x.ToString()).ToArray()));
public int Id {get; set;}
public string Libelle {get; set;}
public override string ToString()
return string.Format("{0}-{1}", Id, Libelle);