Guest User

Untitled

a guest
May 25th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. Dictionary<string,object>
  2.  
  3. var name="name";
  4.  
  5. var obj = new { name = new object(), };
  6.  
  7. var lookup = new Dictionary<string,object>();
  8.  
  9.  
  10. if(obj.GetType().Name.StartsWith("<>f__AnonymousType"))
  11. {
  12. foreach (var property in obj.GetType().GetProperties())
  13. {
  14. lookup[property.Name] = property.GetValue(obj, null);
  15. }
  16. }
  17. else
  18. {
  19. lookup[name]=obj;
  20. }
  21.  
  22. Dictionary<string,object>
  23.  
  24. var dic = obj.GetType()
  25. .GetProperties()
  26. .ToDictionary(p => p.Name, p=> p.GetValue(obj, null));
  27.  
  28. var obj = new Dictionary<string, object>()
  29. {
  30. { "Name", t.Name },
  31. { "Value", t.Value }
  32. };
Add Comment
Please, Sign In to add comment