Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. public static Dictionary<string, Type> GetTypeJsonPropertyNamesAndTypes<T>()
  2.         {
  3.             var pairs = typeof(T)
  4.                 .GetProperties()
  5.                 .Select(p => new {
  6.                     Property = p,
  7.                     Attribute = p
  8.                         .GetCustomAttributes(
  9.                             typeof(JsonPropertyAttribute), true)
  10.                         .Cast<JsonPropertyAttribute>()
  11.                         .FirstOrDefault()
  12.                 });
  13.  
  14.             return pairs
  15.                 .Where(p => p.Attribute != null)
  16.                 .ToDictionary(
  17.                     p => p.Attribute.PropertyName,
  18.                     p => p.Property.PropertyType);
  19.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement