Json.NET
Code Coverage Statistics for Source File

Newtonsoft.Json\Bson\BsonToken.cs

Symbol Coverage: 92.86% (26 of 28)

Branch Coverage: 94.44% (17 of 18)

Cyclomatic Complexity Avg: 1.00 Max:1

Code Lines: 33


L V Source
1
using System.Collections;
2
using System.Collections.Generic;
3

  
4
namespace Newtonsoft.Json.Bson
5
{
6
  internal abstract class BsonToken
7
  {
8
    public abstract BsonType Type { get; }
9
    public BsonToken Parent { get; set; }
10
    public int CalculatedSize { get; set; }
11
  }
12

  
13
  internal class BsonObject : BsonToken, IEnumerable<BsonProperty>
14
  {
15
 126275
    private readonly List<BsonProperty> _children = new List<BsonProperty>();
16

  
17
    public void Add(string name, BsonToken token)
18
    {
19
 399791
      _children.Add(new BsonProperty { Name = new BsonString(name, false), Value = token });
20
 399791
      token.Parent = this;
21
 399791
    }
22

  
23
    public override BsonType Type
24
    {
25
 368390
      get { return BsonType.Object; }
26
    }
27

  
28
    public IEnumerator<BsonProperty> GetEnumerator()
29
    {
30
 252550
      return _children.GetEnumerator();
31
 252550
    }
32

  
33
    IEnumerator IEnumerable.GetEnumerator()
34
    {
35
 0
      return GetEnumerator();
36
 0
    }
37
  }
38

  
39
  internal class BsonArray : BsonToken, IEnumerable<BsonToken>
40
  {
41
 10425
    private readonly List<BsonToken> _children = new List<BsonToken>();
42

  
43
    public void Add(BsonToken token)
44
    {
45
 26090
      _children.Add(token);
46
 26090
      token.Parent = this;
47
 26090
    }
48

  
49
    public override BsonType Type
50
    {
51
 31259
      get { return BsonType.Array; }
52
    }
53

  
54
    public IEnumerator<BsonToken> GetEnumerator()
55
    {
56
 20842
      return _children.GetEnumerator();
57
 20842
    }
58

  
59
    IEnumerator IEnumerable.GetEnumerator()
60
    {
61
 0
      return GetEnumerator();
62
 0
    }
63
  }
64

  
65
  internal class BsonValue : BsonToken
66
  {
67
    private object _value;
68
    private BsonType _type;
69

  
70
 699420
    public BsonValue(object value, BsonType type)
71
    {
72
 699420
      _value = value;
73
 699420
      _type = type;
74
 699420
    }
75

  
76
    public object Value
77
    {
78
 1247122
      get { return _value; }
79
    }
80

  
81
    public override BsonType Type
82
    {
83
 1298658
      get { return _type; }
84
    }
85
  }
86

  
87
  internal class BsonString : BsonValue
88
  {
89
    public int ByteCount { get; set; }
90
    public bool IncludeLength { get; set; }
91

  
92
 542093
    public BsonString(object value, bool includeLength)
93
 542093
      : base(value, BsonType.String)
94
    {
95
 542093
      IncludeLength = includeLength;
96
 542093
    }
97
  }
98

  
99
  internal class BsonRegex : BsonToken
100
  {
101
    public BsonString Pattern { get; set; }
102
    public BsonString Options { get; set; }
103

  
104
 5
    public BsonRegex(string pattern, string options)
105
    {
106
 5
      Pattern = new BsonString(pattern, false);
107
 5
      Options = new BsonString(options, false);
108
 5
    }
109

  
110
    public override BsonType Type
111
    {
112
 15
      get { return BsonType.Regex; }
113
    }
114
  }
115

  
116
  internal class BsonProperty
117
  {
118
    public BsonString Name { get; set; }
119
    public BsonToken Value { get; set; }
120
  }
121
}