1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- /* ==============================================================================
- * 功能描述:ParameterConverter
- * 创 建 者:Garrett
- * 创建日期:2019/6/26 10:14:23
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using JBIM.Component;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- namespace RevitToJBim.JsonConverter
- {
- /// <summary>
- /// ParameterDefinationConverter
- /// </summary>
- class ParameterConverter : Newtonsoft.Json.JsonConverter
- {
- public override bool CanConvert(Type objectType)
- {
- return objectType == typeof(Parameter);
- }
- public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
- {
- throw new NotImplementedException();
- }
- public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
- {
- if (value == null)
- {
- writer.WriteNull();
- return;
- }
- JObject jObject=new JObject();
- var parameter = value as Parameter;
- if (parameter == null) return;
- jObject.Add("Name", parameter?.Definition?.Name);
- jObject.Add("Value",parameter?.Value);
- writer.WriteToken(jObject.CreateReader());
- }
- }
- }
|