You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuPartialJsonWriter.cs 1.1KB

123456789101112131415161718192021222324252627282930
  1. using System.IO;
  2. using Luticate2.Auth.Utils.Business.Fields;
  3. using Luticate2.Auth.Utils.Dbo.Fields;
  4. using Newtonsoft.Json;
  5. namespace Luticate2.Auth.Utils.Business.Serializers.PartialJson
  6. {
  7. public static class LuPartialJsonWriter
  8. {
  9. public static string SerializeObject(object data, LuPartialFieldsDbo partialResponseDbo, JsonSerializerSettings settings)
  10. {
  11. var stringWriter = new StringWriter();
  12. SerializeObject(data, partialResponseDbo, settings, stringWriter);
  13. var result = stringWriter.ToString();
  14. return result;
  15. }
  16. public static void SerializeObject(object data, LuPartialFieldsDbo partialResponseDbo, JsonSerializerSettings settings, TextWriter writer)
  17. {
  18. using (var jsonWriter = new JsonTextWriter(writer))
  19. {
  20. jsonWriter.CloseOutput = false;
  21. var jsonSerializer = JsonSerializer.Create(settings);
  22. jsonSerializer.Serialize(jsonWriter, data, path => partialResponseDbo.Fields.IsIncluded(path));
  23. }
  24. }
  25. }
  26. }