-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSqlTypesJsonConverter.cs
More file actions
41 lines (36 loc) · 1.37 KB
/
Copy pathSqlTypesJsonConverter.cs
File metadata and controls
41 lines (36 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Newtonsoft.Json;
using System;
namespace pod.xledger.sql_server;
public class SqlTypesJsonConverter : JsonConverter {
public override bool CanConvert(Type objectType) {
return objectType.Namespace == "Microsoft.SqlServer.Types";
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
if (value == null) {
writer.WriteNull();
return;
}
if (value is Microsoft.SqlServer.Types.SqlHierarchyId hier) {
if (hier.IsNull) { writer.WriteNull(); } else {
writer.WriteValue(hier.ToString());
}
} else if (value is Microsoft.SqlServer.Types.SqlGeography geog) {
if (geog.IsNull) {
writer.WriteNull();
} else {
writer.WriteValue(geog.ToString());
}
} else if (value is Microsoft.SqlServer.Types.SqlGeometry geom) {
if (geom.IsNull) {
writer.WriteNull();
} else {
writer.WriteValue(geom.ToString());
}
} else {
writer.WriteValue(value.ToString());
}
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
throw new NotImplementedException();
}
}