-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathInterfaceContractResolver.cs
43 lines (37 loc) · 1.33 KB
/
InterfaceContractResolver.cs
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
42
43
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace RevitGltfExporter
{
class InterfaceContractResolver : DefaultContractResolver
{
//private readonly Type[] _interfaceTypes;
//private readonly ConcurrentDictionary<Type, Type> _typeToSerializeMap;
private readonly Type _interfaceType;
public InterfaceContractResolver(Type interfaceType)
{
//_interfaceTypes = interfaceTypes;
//_typeToSerializeMap = new ConcurrentDictionary<Type, Type>();
this._interfaceType = interfaceType;
}
protected override IList<JsonProperty> CreateProperties(
Type type,
MemberSerialization memberSerialization)
{
//var typeToSerialize = _typeToSerializeMap.GetOrAdd(
// type,
// t => _interfaceTypes.FirstOrDefault(
// it => it.IsAssignableFrom(t)) ?? t);
if (this._interfaceType.IsAssignableFrom(type))
{
return base.CreateProperties(this._interfaceType, memberSerialization);
}
return base.CreateProperties(type, memberSerialization);
}
}
}