2
// Copyright (c) 2007 James Newton-King
4
// Permission is hereby granted, free of charge, to any person
5
// obtaining a copy of this software and associated documentation
6
// files (the "Software"), to deal in the Software without
7
// restriction, including without limitation the rights to use,
8
// copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the
10
// Software is furnished to do so, subject to the following
13
// The above copyright notice and this permission notice shall be
14
// included in all copies or substantial portions of the Software.
16
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
// OTHER DEALINGS IN THE SOFTWARE.
26
using System.Collections;
27
using System.Collections.Generic;
29
namespace Newtonsoft.Json.Bson
31
internal abstract class BsonToken
33
public abstract BsonType Type { get; }
34
public BsonToken Parent { get; set; }
35
public int CalculatedSize { get; set; }
38
internal class BsonObject : BsonToken, IEnumerable<BsonProperty>
40
private readonly List<BsonProperty> _children = new List<BsonProperty>();
42
public void Add(string name, BsonToken token)
44
_children.Add(new BsonProperty { Name = new BsonString(name, false), Value = token });
48
public override BsonType Type
50
get { return BsonType.Object; }
53
public IEnumerator<BsonProperty> GetEnumerator()
55
return _children.GetEnumerator();
58
IEnumerator IEnumerable.GetEnumerator()
60
return GetEnumerator();
64
internal class BsonArray : BsonToken, IEnumerable<BsonToken>
66
private readonly List<BsonToken> _children = new List<BsonToken>();
68
public void Add(BsonToken token)
74
public override BsonType Type
76
get { return BsonType.Array; }
79
public IEnumerator<BsonToken> GetEnumerator()
81
return _children.GetEnumerator();
84
IEnumerator IEnumerable.GetEnumerator()
86
return GetEnumerator();
90
internal class BsonValue : BsonToken
92
private readonly object _value;
93
private readonly BsonType _type;
95
public BsonValue(object value, BsonType type)
103
get { return _value; }
106
public override BsonType Type
108
get { return _type; }
112
internal class BsonString : BsonValue
114
public int ByteCount { get; set; }
115
public bool IncludeLength { get; set; }
117
public BsonString(object value, bool includeLength)
118
: base(value, BsonType.String)
120
IncludeLength = includeLength;
124
internal class BsonRegex : BsonToken
126
public BsonString Pattern { get; set; }
127
public BsonString Options { get; set; }
129
public BsonRegex(string pattern, string options)
131
Pattern = new BsonString(pattern, false);
132
Options = new BsonString(options, false);
135
public override BsonType Type
137
get { return BsonType.Regex; }
141
internal class BsonProperty
143
public BsonString Name { get; set; }
144
public BsonToken Value { get; set; }
b'\\ No newline at end of file'