Guest User

Untitled

a guest
Jun 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. using Newtonsoft.Json;
  2. using System.Collections.Generic;
  3.  
  4. public static string FromClass<T>(T data, bool isEmptyToNull = false,
  5. JsonSerializerSettings jsonSettings = null)
  6. {
  7. string response = string.Empty;
  8.  
  9. if (!EqualityComparer<T>.Default.Equals(data, default(T)))
  10. response = JsonConvert.SerializeObject(data, jsonSettings);
  11.  
  12. return isEmptyToNull ? (response == "{}" ? "null" : response) : response;
  13. }
Add Comment
Please, Sign In to add comment