-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ricaun-io/develop
Version 1.0.3
- Loading branch information
Showing
5 changed files
with
102 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
ricaun.Revit.ExtensibleJson/Converters/ObjectJsonConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
|
||
namespace ricaun.Revit.ExtensibleJson.Converters | ||
{ | ||
/// <summary> | ||
/// ObjectJsonConverter | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
public abstract class ObjectJsonConverter<T> : JsonConverter | ||
{ | ||
/// <summary> | ||
/// Convert <paramref name="value"/> to <typeparamref name="T"/> | ||
/// </summary> | ||
/// <param name="value"></param> | ||
/// <returns></returns> | ||
public abstract T Read(JObject value); | ||
|
||
/// <summary> | ||
/// Convert <paramref name="value"/> to object | ||
/// </summary> | ||
/// <param name="value"></param> | ||
/// <returns></returns> | ||
public abstract object Write(T value); | ||
|
||
/// <summary> | ||
/// Check type equal to <typeparamref name="T"/> | ||
/// </summary> | ||
/// <param name="objectType"></param> | ||
/// <returns></returns> | ||
public override bool CanConvert(Type objectType) | ||
{ | ||
return objectType == typeof(T); | ||
} | ||
|
||
/// <summary> | ||
/// ReadJson | ||
/// </summary> | ||
/// <param name="reader"></param> | ||
/// <param name="objectType"></param> | ||
/// <param name="existingValue"></param> | ||
/// <param name="serializer"></param> | ||
/// <returns></returns> | ||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
return Read(JObject.Load(reader)); | ||
} | ||
|
||
/// <summary> | ||
/// WriteJson | ||
/// </summary> | ||
/// <param name="writer"></param> | ||
/// <param name="value"></param> | ||
/// <param name="serializer"></param> | ||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
JToken.FromObject(Write((T)value)) | ||
.WriteTo(writer); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters