68 lines
2.8 KiB
C#
68 lines
2.8 KiB
C#
|
/************************************************************************
|
|||
|
* ClassName : ElementIdConverter
|
|||
|
* Description :
|
|||
|
* Author : Einsam
|
|||
|
* CreateTime : 2019/4/1 17:40:38
|
|||
|
************************************************************************
|
|||
|
* █████▒█ ██ ▄████▄ ██ ▄█▀ ██████╗ ██╗ ██╗ ██████╗
|
|||
|
* ▓██ ▒ ██ ▓██▒▒██▀ ▀█ ██▄█▒ ██╔══██╗██║ ██║██╔════╝
|
|||
|
* ▒████ ░▓██ ▒██░▒▓█ ▄ ▓███▄░ ██████╔╝██║ ██║██║ ███╗
|
|||
|
* ░▓█▒ ░▓▓█ ░██░▒▓▓▄ ▄██▒▓██ █▄ ██╔══██╗██║ ██║██║ ██║
|
|||
|
* ░▒█░ ▒▒█████▓ ▒ ▓███▀ ░▒██▒ █▄ ██████╔╝╚██████╔╝╚██████╔╝
|
|||
|
* ▒ ░ ░▒▓▒ ▒ ▒ ░ ░▒ ▒ ░▒ ▒▒ ▓▒ ╚═════╝ ╚═════╝ ╚═════╝
|
|||
|
* ░ ░░▒░ ░ ░ ░ ▒ ░ ░▒ ▒░
|
|||
|
* ░ ░ ░░░ ░ ░ ░ ░ ░░ ░
|
|||
|
* ░ ░ ░ ░ ░
|
|||
|
* ░
|
|||
|
************************************************************************
|
|||
|
* Copyright @ u-BIM Dev. 2018 . All rights reserved.
|
|||
|
************************************************************************/
|
|||
|
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using Autodesk.Revit.DB;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using Newtonsoft.Json.Linq;
|
|||
|
|
|||
|
namespace GraphicsStudy.Json
|
|||
|
{
|
|||
|
public class ElementIdConverter : Newtonsoft.Json.JsonConverter
|
|||
|
{
|
|||
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
|||
|
{
|
|||
|
if (value == null)
|
|||
|
{
|
|||
|
writer.WriteNull();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
JObject jObject = new JObject();
|
|||
|
jObject.Add("ID", (value as ElementId).IntegerValue);
|
|||
|
writer.WriteValue(jObject.ToString());
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
|||
|
{
|
|||
|
var jObject = JObject.Parse(reader.Value as string);
|
|||
|
|
|||
|
int id = jObject.Value<int>("ID");
|
|||
|
|
|||
|
return new ElementId(id);
|
|||
|
}
|
|||
|
|
|||
|
public override bool CanConvert(Type objectType)
|
|||
|
{
|
|||
|
if (objectType == typeof(ElementId))
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|