Advertisement
Guest User

map.cs

a guest
Apr 17th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. public void Map<T>(T ctorObj)
  2. {
  3. string[] localNames = this.GetType().GetMembers().Where(m => m.MemberType.ToString() == "Property").Select(m => m.Name).ToArray();
  4. string[] ctorNames = typeof(T).GetMembers().Where(m => m.MemberType.ToString() == "Property").Select(m => m.Name).ToArray();
  5. string[] names = localNames.Intersect(ctorNames).ToArray();
  6. foreach (string s in names)
  7. {
  8. PropertyInfo propSet = this.GetType().GetProperty(s);
  9. PropertyInfo propGet = typeof(T).GetProperty(s);
  10. propSet.SetValue(this, propGet.GetValue(ctorObj, null));
  11. }
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement