forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializerOptions.cs
More file actions
75 lines (66 loc) · 3.17 KB
/
SerializerOptions.cs
File metadata and controls
75 lines (66 loc) · 3.17 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// -----------------------------------------------------------------------
// <copyright file="SerializerOptions.cs" company="Asynkron HB">
// Copyright (C) 2015-2017 Asynkron HB All rights reserved
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using Wire.SerializerFactories;
namespace Wire
{
public class SerializerOptions
{
internal static readonly Surrogate[] EmptySurrogates = new Surrogate[0];
internal static readonly ValueSerializerFactory[] EmptyValueSerializerFactories = new ValueSerializerFactory[0];
private static readonly ValueSerializerFactory[] DefaultValueSerializerFactories =
{
new ConsistentArraySerializerFactory(),
new MethodInfoSerializerFactory(),
new PropertyInfoSerializerFactory(),
new ConstructorInfoSerializerFactory(),
new FieldInfoSerializerFactory(),
new DelegateSerializerFactory(),
new ToSurrogateSerializerFactory(),
new FromSurrogateSerializerFactory(),
new FSharpMapSerializerFactory(),
new FSharpListSerializerFactory(),
//order is important, try dictionaries before enumerables as dicts are also enumerable
new ExceptionSerializerFactory(),
new ImmutableCollectionsSerializerFactory(),
new ExpandoObjectSerializerFactory(),
new DefaultDictionarySerializerFactory(),
new LinkedListSerializerFactory(),
new DictionarySerializerFactory(),
new HashSetSerializerFactory(),
new ArraySerializerFactory(),
#if NET45
new ISerializableSerializerFactory(), //TODO: this will mess up the indexes in the serializer payload
#endif
new EnumerableSerializerFactory()
};
internal readonly Type[] KnownTypes;
internal readonly Dictionary<Type, ushort> KnownTypesDict = new Dictionary<Type, ushort>();
internal readonly bool PreserveObjectReferences;
internal readonly Surrogate[] Surrogates;
internal readonly ValueSerializerFactory[] ValueSerializerFactories;
internal readonly bool VersionTolerance;
public SerializerOptions(bool versionTolerance = false, bool preserveObjectReferences = false,
IEnumerable<Surrogate> surrogates = null, IEnumerable<ValueSerializerFactory> serializerFactories = null,
IEnumerable<Type> knownTypes = null)
{
VersionTolerance = versionTolerance;
Surrogates = surrogates?.ToArray() ?? EmptySurrogates;
//use the default factories + any user defined
ValueSerializerFactories =
DefaultValueSerializerFactories.Concat(serializerFactories?.ToArray() ?? EmptyValueSerializerFactories)
.ToArray();
KnownTypes = knownTypes?.ToArray() ?? new Type[] {};
for (var i = 0; i < KnownTypes.Length; i++)
{
KnownTypesDict.Add(KnownTypes[i], (ushort) i);
}
PreserveObjectReferences = preserveObjectReferences;
}
}
}