Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. public class BaseDto
  2. {
  3. public int ID{ get; set; }
  4. }
  5. public class Client: BaseDto
  6. {
  7. public string Surname { get; set; }
  8. public string FirstName{ get; set; }
  9. public string email{ get; set; }
  10. }
  11.  
  12. PropertyInfo[] props = typeof(Client).GetProperties();
  13.  
  14. Type type = typeof(Client);
  15. List<Type> types = new List<Type>();
  16. do
  17. {
  18. types.Insert(0, type);
  19. type = type.BaseType;
  20. } while (type.BaseType!=null);
  21.  
  22. PropertyInfo[] props = typeof(Client).GetProperties()
  23. .OrderBy(x => types.IndexOf(x.DeclaringType))
  24. .ToArray();
  25.  
  26. typeof(Client).BaseType
  27.  
  28. BindingFlags.DeclaredOnly
  29.  
  30. var baseProps = typeof(BaseDto).GetProperties();
  31. var props = typeof(Client).GetProperties();
  32.  
  33. var allProps = baseProps
  34. .Concat(props.Where(p => baseProps
  35. .Select(b => b.Name)
  36. .Contains(p.Name) == false));
  37.  
  38. Dictionary<string, PropertyInfo> _PropertyIndex = new Dictionary<string, PropertyInfo>();
  39.  
  40. Type thisType = typeof(Client);
  41.  
  42. foreach (PropertyInfo pi in thisType.BaseType.GetProperties())
  43. _PropertyIndex.Add(pi.Name.ToUpper(), pi);
  44. foreach (PropertyInfo pi in thisType.GetProperties())
  45. if( !_PropertyIndex.ContainsKey(pi.Name.ToUpper()))
  46. _PropertyIndex.Add(pi.Name.ToUpper(), pi);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement