forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsState.cs
More file actions
79 lines (60 loc) · 1.93 KB
/
JsState.cs
File metadata and controls
79 lines (60 loc) · 1.93 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
76
77
78
79
using System;
using System.Collections.Generic;
namespace ServiceStack.Text.Common
{
internal static class JsState
{
//Exposing field for perf
[ThreadStatic]
internal static int WritingKeyCount = 0;
[ThreadStatic]
internal static bool IsWritingValue = false;
[ThreadStatic]
internal static bool IsWritingDynamic = false;
[ThreadStatic]
internal static bool QueryStringMode = false;
[ThreadStatic]
internal static int Depth = 0;
[ThreadStatic]
internal static HashSet<Type> InSerializerFns = new HashSet<Type>();
internal static void RegisterSerializer<T>()
{
if (InSerializerFns == null)
InSerializerFns = new HashSet<Type>();
InSerializerFns.Add(typeof(T));
}
internal static void UnRegisterSerializer<T>()
{
if (InSerializerFns == null)
return;
InSerializerFns.Remove(typeof(T));
}
internal static bool InSerializer<T>()
{
return InSerializerFns != null && InSerializerFns.Contains(typeof(T));
}
[ThreadStatic]
internal static HashSet<Type> InDeserializerFns;
internal static void RegisterDeserializer<T>()
{
if (InDeserializerFns == null)
InDeserializerFns = new HashSet<Type>();
InDeserializerFns.Add(typeof(T));
}
internal static void UnRegisterDeserializer<T>()
{
if (InDeserializerFns == null)
return;
InDeserializerFns.Remove(typeof(T));
}
internal static bool InDeserializer<T>()
{
return InDeserializerFns != null && InDeserializerFns.Contains(typeof(T));
}
internal static void Reset()
{
InSerializerFns = null;
InDeserializerFns = null;
}
}
}