Get a list of JSON property names from a class to use in a query string

后端 未结 4 1351
清歌不尽
清歌不尽 2020-12-10 11:48

If I have a C# model class that is used by JSON.net to bind data from a serialized JSON string, is there a way that I can create a query string from that class in order to m

4条回答
  •  Happy的楠姐
    2020-12-10 12:31

    A small variation of @Brian Rogers solution that solve null exception problem:

    IEnumerable props = typeof(T).GetProperties()
                                         .Select(p => p.GetCustomAttribute())
                                         .Where(jp => jp != null)
                                         .Select(jp => jp.PropertyName);
    
    string propsList = string.Join(',', props);
    

提交回复
热议问题