Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. public Dictionary<string, object> ToDictionary()
  2. {
  3. return this.GetType()
  4. .GetProperties(BindingFlags.Instance | BindingFlags.Public)
  5. .Where(prop => prop.GetCustomAttribute<JsonPropertyAttribute>() != null && prop.GetValue(this, null) != null && !string.IsNullOrEmpty(prop.GetValue(this, null).ToString()))
  6. .ToDictionary(prop => prop.GetCustomAttribute<JsonPropertyAttribute>().PropertyName, prop => prop.GetValue(this, null));
  7. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement