ParameterConverter.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* ==============================================================================
  2. * 功能描述:ParameterConverter
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/6/26 10:14:23
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using JBIM.Component;
  12. using Newtonsoft.Json;
  13. using Newtonsoft.Json.Linq;
  14. namespace RevitToJBim.JsonConverter
  15. {
  16. /// <summary>
  17. /// ParameterDefinationConverter
  18. /// </summary>
  19. class ParameterConverter : Newtonsoft.Json.JsonConverter
  20. {
  21. public override bool CanConvert(Type objectType)
  22. {
  23. return objectType == typeof(Parameter);
  24. }
  25. public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
  26. {
  27. throw new NotImplementedException();
  28. }
  29. public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
  30. {
  31. if (value == null)
  32. {
  33. writer.WriteNull();
  34. return;
  35. }
  36. JObject jObject=new JObject();
  37. var parameter = value as Parameter;
  38. if (parameter == null) return;
  39. jObject.Add("Name", parameter?.Definition?.Name);
  40. jObject.Add("Value",parameter?.Value);
  41. writer.WriteToken(jObject.CreateReader());
  42. }
  43. }
  44. }