本文整理汇总了C#中Newtonsoft.Json.Bson.BsonToken类的典型用法代码示例。如果您正苦于以下问题:C# BsonToken类的具体用法?C# BsonToken怎么用?C# BsonToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonToken类属于Newtonsoft.Json.Bson命名空间,在下文中一共展示了BsonToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddToken
internal void AddToken(BsonToken token)
{
if (_parent != null)
{
if (_parent is BsonObject)
{
((BsonObject)_parent).Add(_propertyName, token);
_propertyName = null;
}
else
{
((BsonArray)_parent).Add(token);
}
}
else
{
_parent = token;
_root = token;
}
}
示例2: WriteTokenInternal
private void WriteTokenInternal(BsonToken t)
{
switch (t.Type)
{
case BsonType.Object:
{
BsonObject value = (BsonObject)t;
_writer.Write(value.CalculatedSize);
foreach (BsonProperty property in value)
{
_writer.Write((sbyte)property.Value.Type);
WriteString((string)property.Name.Value, property.Name.ByteCount, null);
WriteTokenInternal(property.Value);
}
_writer.Write((byte)0);
}
break;
case BsonType.Array:
{
BsonArray value = (BsonArray)t;
_writer.Write(value.CalculatedSize);
int index = 0;
foreach (BsonToken c in value)
{
_writer.Write((sbyte)c.Type);
WriteString(index.ToString(CultureInfo.InvariantCulture), MathUtils.IntLength(index), null);
WriteTokenInternal(c);
index++;
}
_writer.Write((byte)0);
}
break;
case BsonType.Integer:
{
BsonValue value = (BsonValue)t;
_writer.Write(Convert.ToInt32(value.Value, CultureInfo.InvariantCulture));
}
break;
case BsonType.Long:
{
BsonValue value = (BsonValue)t;
_writer.Write(Convert.ToInt64(value.Value, CultureInfo.InvariantCulture));
}
break;
case BsonType.Number:
{
BsonValue value = (BsonValue)t;
_writer.Write(Convert.ToDouble(value.Value, CultureInfo.InvariantCulture));
}
break;
case BsonType.String:
{
BsonString value = (BsonString)t;
WriteString((string)value.Value, value.ByteCount, value.CalculatedSize - 4);
}
break;
case BsonType.Boolean:
{
BsonValue value = (BsonValue)t;
_writer.Write((bool)value.Value);
}
break;
case BsonType.Null:
case BsonType.Undefined:
break;
case BsonType.Date:
{
BsonValue value = (BsonValue)t;
long ticks = 0;
if (value.Value is DateTime)
{
DateTime dateTime = (DateTime)value.Value;
if (DateTimeKindHandling == DateTimeKind.Utc)
dateTime = dateTime.ToUniversalTime();
else if (DateTimeKindHandling == DateTimeKind.Local)
dateTime = dateTime.ToLocalTime();
ticks = JsonConvert.ConvertDateTimeToJavaScriptTicks(dateTime, false);
}
#if !PocketPC && !NET20
else
{
DateTimeOffset dateTimeOffset = (DateTimeOffset)value.Value;
ticks = JsonConvert.ConvertDateTimeToJavaScriptTicks(dateTimeOffset.UtcDateTime, dateTimeOffset.Offset);
}
#endif
_writer.Write(ticks);
}
break;
case BsonType.Binary:
{
BsonValue value = (BsonValue)t;
byte[] data = (byte[])value.Value;
_writer.Write(data.Length);
_writer.Write((byte)BsonBinaryType.Binary);
_writer.Write(data);
//.........这里部分代码省略.........
示例3: CalculateSize
private int CalculateSize(BsonToken t)
{
switch (t.Type)
{
case BsonType.Object:
{
BsonObject value = (BsonObject)t;
int bases = 4;
foreach (BsonProperty p in value)
{
int size = 1;
size += CalculateSize(p.Name);
size += CalculateSize(p.Value);
bases += size;
}
bases += 1;
value.CalculatedSize = bases;
return bases;
}
case BsonType.Array:
{
BsonArray value = (BsonArray)t;
int size = 4;
int index = 0;
foreach (BsonToken c in value)
{
size += 1;
size += CalculateSize(MathUtils.IntLength(index));
size += CalculateSize(c);
index++;
}
size += 1;
value.CalculatedSize = size;
return value.CalculatedSize;
}
case BsonType.Integer:
return 4;
case BsonType.Long:
return 8;
case BsonType.Number:
return 8;
case BsonType.String:
{
BsonString value = (BsonString)t;
string s = (string)value.Value;
value.ByteCount = (s != null) ? Encoding.GetByteCount(s) : 0;
value.CalculatedSize = CalculateSizeWithLength(value.ByteCount, value.IncludeLength);
return value.CalculatedSize;
}
case BsonType.Boolean:
return 1;
case BsonType.Null:
case BsonType.Undefined:
return 0;
case BsonType.Date:
return 8;
case BsonType.Binary:
{
BsonValue value = (BsonValue)t;
byte[] data = (byte[])value.Value;
value.CalculatedSize = 4 + 1 + data.Length;
return value.CalculatedSize;
}
case BsonType.Oid:
return 12;
case BsonType.Regex:
{
BsonRegex value = (BsonRegex)t;
int size = 0;
size += CalculateSize(value.Pattern);
size += CalculateSize(value.Options);
value.CalculatedSize = size;
return value.CalculatedSize;
}
default:
throw new ArgumentOutOfRangeException("t", "Unexpected token when writing BSON: {0}".FormatWith(CultureInfo.InvariantCulture, t.Type));
}
}
示例4: AddParent
private void AddParent(BsonToken container)
{
AddToken(container);
_parent = container;
}
示例5: WriteToken
// Token: 0x0600004F RID: 79
// RVA: 0x00005F13 File Offset: 0x00004113
public void WriteToken(BsonToken t)
{
this.CalculateSize(t);
this.WriteTokenInternal(t);
}
示例6: AddToken
internal void AddToken(BsonToken token)
{
if (_parent != null)
{
if (_parent is BsonObject)
{
((BsonObject) _parent).Add(_propertyName, token);
_propertyName = null;
}
else
{
((BsonArray) _parent).Add(token);
}
}
else
{
if (token.Type != BsonType.Object && token.Type != BsonType.Array)
throw new JsonWriterException("Error writing {0} value. BSON must start with an Object or Array.".FormatWith(CultureInfo.InvariantCulture, token.Type));
_parent = token;
_root = token;
}
}
示例7: CalculateSize
// Token: 0x06000055 RID: 85
// RVA: 0x000289C0 File Offset: 0x00026BC0
private int CalculateSize(BsonToken t)
{
switch (t.Type)
{
case BsonType.Number:
return 8;
case BsonType.String:
{
BsonString bsonString = (BsonString)t;
string text = (string)bsonString.Value;
bsonString.ByteCount = ((text != null) ? BsonBinaryWriter.Encoding.GetByteCount(text) : 0);
bsonString.CalculatedSize = this.CalculateSizeWithLength(bsonString.ByteCount, bsonString.IncludeLength);
return bsonString.CalculatedSize;
}
case BsonType.Object:
{
BsonObject bsonObject = (BsonObject)t;
int num = 4;
foreach (BsonProperty current in bsonObject)
{
int num2 = 1 + this.CalculateSize(current.Name);
num2 += this.CalculateSize(current.Value);
num += num2;
}
num++;
bsonObject.CalculatedSize = num;
return num;
}
case BsonType.Array:
{
BsonArray bsonArray = (BsonArray)t;
int num3 = 4;
ulong num4 = 0uL;
foreach (BsonToken current2 in bsonArray)
{
num3++;
num3 += this.CalculateSize(MathUtils.IntLength(num4));
num3 += this.CalculateSize(current2);
num4 += 1uL;
}
num3++;
bsonArray.CalculatedSize = num3;
return bsonArray.CalculatedSize;
}
case BsonType.Binary:
{
BsonBinary bsonBinary = (BsonBinary)t;
byte[] array = (byte[])bsonBinary.Value;
bsonBinary.CalculatedSize = 5 + array.Length;
return bsonBinary.CalculatedSize;
}
case BsonType.Undefined:
case BsonType.Null:
return 0;
case BsonType.Oid:
return 12;
case BsonType.Boolean:
return 1;
case BsonType.Date:
return 8;
case BsonType.Regex:
{
BsonRegex bsonRegex = (BsonRegex)t;
int num5 = 0 + this.CalculateSize(bsonRegex.Pattern);
num5 += this.CalculateSize(bsonRegex.Options);
bsonRegex.CalculatedSize = num5;
return bsonRegex.CalculatedSize;
}
case BsonType.Integer:
return 4;
case BsonType.Long:
return 8;
}
throw new ArgumentOutOfRangeException("t", StringUtils.FormatWith("Unexpected token when writing BSON: {0}", CultureInfo.InvariantCulture, t.Type));
}
示例8: WriteTokenInternal
// Token: 0x06000050 RID: 80
// RVA: 0x0002854C File Offset: 0x0002674C
private void WriteTokenInternal(BsonToken t)
{
switch (t.Type)
{
case BsonType.Number:
{
BsonValue bsonValue = (BsonValue)t;
this._writer.Write(Convert.ToDouble(bsonValue.Value, CultureInfo.InvariantCulture));
return;
}
case BsonType.String:
{
BsonString bsonString = (BsonString)t;
this.WriteString((string)bsonString.Value, bsonString.ByteCount, new int?(bsonString.CalculatedSize - 4));
return;
}
case BsonType.Object:
{
BsonObject bsonObject = (BsonObject)t;
this._writer.Write(bsonObject.CalculatedSize);
foreach (BsonProperty current in bsonObject)
{
this._writer.Write((sbyte)current.Value.Type);
this.WriteString((string)current.Name.Value, current.Name.ByteCount, null);
this.WriteTokenInternal(current.Value);
}
this._writer.Write(0);
return;
}
case BsonType.Array:
{
BsonArray bsonArray = (BsonArray)t;
this._writer.Write(bsonArray.CalculatedSize);
ulong num = 0uL;
foreach (BsonToken current2 in bsonArray)
{
this._writer.Write((sbyte)current2.Type);
this.WriteString(num.ToString(CultureInfo.InvariantCulture), MathUtils.IntLength(num), null);
this.WriteTokenInternal(current2);
num += 1uL;
}
this._writer.Write(0);
return;
}
case BsonType.Binary:
{
BsonBinary bsonBinary = (BsonBinary)t;
byte[] array = (byte[])bsonBinary.Value;
this._writer.Write(array.Length);
this._writer.Write((byte)bsonBinary.BinaryType);
this._writer.Write(array);
return;
}
case BsonType.Undefined:
case BsonType.Null:
return;
case BsonType.Oid:
{
BsonValue bsonValue2 = (BsonValue)t;
byte[] buffer = (byte[])bsonValue2.Value;
this._writer.Write(buffer);
return;
}
case BsonType.Boolean:
{
BsonValue bsonValue3 = (BsonValue)t;
this._writer.Write((bool)bsonValue3.Value);
return;
}
case BsonType.Date:
{
BsonValue bsonValue4 = (BsonValue)t;
long value = 0L;
if (bsonValue4.Value is DateTime)
{
DateTime dateTime = (DateTime)bsonValue4.Value;
if (this.DateTimeKindHandling == DateTimeKind.Utc)
{
dateTime = dateTime.ToUniversalTime();
}
else if (this.DateTimeKindHandling == DateTimeKind.Local)
{
dateTime = dateTime.ToLocalTime();
}
value = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(dateTime, false);
}
this._writer.Write(value);
return;
}
case BsonType.Regex:
{
BsonRegex bsonRegex = (BsonRegex)t;
this.WriteString((string)bsonRegex.Pattern.Value, bsonRegex.Pattern.ByteCount, null);
this.WriteString((string)bsonRegex.Options.Value, bsonRegex.Options.ByteCount, null);
return;
}
case BsonType.Integer:
{
//.........这里部分代码省略.........
示例9: AddParent
// Token: 0x0600015C RID: 348
// RVA: 0x00006A7A File Offset: 0x00004C7A
private void AddParent(BsonToken container)
{
this.AddToken(container);
this._parent = container;
}
示例10: AddToken
// Token: 0x0600015F RID: 351
// RVA: 0x0002B358 File Offset: 0x00029558
internal void AddToken(BsonToken token)
{
if (this._parent != null)
{
if (this._parent is BsonObject)
{
((BsonObject)this._parent).Add(this._propertyName, token);
this._propertyName = null;
return;
}
((BsonArray)this._parent).Add(token);
return;
}
else
{
if (token.Type != BsonType.Object && token.Type != BsonType.Array)
{
throw JsonWriterException.Create(this, StringUtils.FormatWith("Error writing {0} value. BSON must start with an Object or Array.", CultureInfo.InvariantCulture, token.Type), null);
}
this._parent = token;
this._root = token;
return;
}
}
示例11: WriteTokenInternal
private void WriteTokenInternal(BsonToken t)
{
switch (t.Type)
{
case BsonType.Number:
this._writer.Write(Convert.ToDouble(((BsonValue) t).Value, (IFormatProvider) CultureInfo.InvariantCulture));
break;
case BsonType.String:
BsonString bsonString = (BsonString) t;
this.WriteString((string) bsonString.Value, bsonString.ByteCount, new int?(bsonString.CalculatedSize - 4));
break;
case BsonType.Object:
BsonObject bsonObject = (BsonObject) t;
this._writer.Write(bsonObject.CalculatedSize);
foreach (BsonProperty bsonProperty in bsonObject)
{
this._writer.Write((sbyte) bsonProperty.Value.Type);
this.WriteString((string) bsonProperty.Name.Value, bsonProperty.Name.ByteCount, new int?());
this.WriteTokenInternal(bsonProperty.Value);
}
this._writer.Write((byte) 0);
break;
case BsonType.Array:
BsonArray bsonArray = (BsonArray) t;
this._writer.Write(bsonArray.CalculatedSize);
int i = 0;
foreach (BsonToken t1 in bsonArray)
{
this._writer.Write((sbyte) t1.Type);
this.WriteString(i.ToString((IFormatProvider) CultureInfo.InvariantCulture), MathUtils.IntLength(i), new int?());
this.WriteTokenInternal(t1);
++i;
}
this._writer.Write((byte) 0);
break;
case BsonType.Binary:
byte[] buffer = (byte[]) ((BsonValue) t).Value;
this._writer.Write(buffer.Length);
this._writer.Write((byte) 0);
this._writer.Write(buffer);
break;
case BsonType.Undefined:
break;
case BsonType.Oid:
this._writer.Write((byte[]) ((BsonValue) t).Value);
break;
case BsonType.Boolean:
this._writer.Write((bool) ((BsonValue) t).Value);
break;
case BsonType.Date:
BsonValue bsonValue = (BsonValue) t;
long num = 0L;
if (bsonValue.Value is DateTime)
{
DateTime dateTime = (DateTime) bsonValue.Value;
if (this.DateTimeKindHandling == DateTimeKind.Utc)
dateTime = dateTime.ToUniversalTime();
else if (this.DateTimeKindHandling == DateTimeKind.Local)
dateTime = dateTime.ToLocalTime();
num = JsonConvert.ConvertDateTimeToJavaScriptTicks(dateTime, false);
}
this._writer.Write(num);
break;
case BsonType.Null:
break;
case BsonType.Regex:
BsonRegex bsonRegex = (BsonRegex) t;
this.WriteString((string) bsonRegex.Pattern.Value, bsonRegex.Pattern.ByteCount, new int?());
this.WriteString((string) bsonRegex.Options.Value, bsonRegex.Options.ByteCount, new int?());
break;
case BsonType.Integer:
this._writer.Write(Convert.ToInt32(((BsonValue) t).Value, (IFormatProvider) CultureInfo.InvariantCulture));
break;
case BsonType.Long:
this._writer.Write(Convert.ToInt64(((BsonValue) t).Value, (IFormatProvider) CultureInfo.InvariantCulture));
break;
default:
throw new ArgumentOutOfRangeException("t", StringUtils.FormatWith("Unexpected token when writing BSON: {0}", (IFormatProvider) CultureInfo.InvariantCulture, (object) t.Type));
}
}
示例12: CalculateSize
private int CalculateSize(BsonToken t)
{
switch (t.Type)
{
case BsonType.Number:
return 8;
case BsonType.String:
BsonString bsonString = (BsonString) t;
string s = (string) bsonString.Value;
bsonString.ByteCount = s != null ? BsonBinaryWriter.Encoding.GetByteCount(s) : 0;
bsonString.CalculatedSize = this.CalculateSizeWithLength(bsonString.ByteCount, bsonString.IncludeLength);
return bsonString.CalculatedSize;
case BsonType.Object:
BsonObject bsonObject = (BsonObject) t;
int num1 = 4;
foreach (BsonProperty bsonProperty in bsonObject)
{
int num2 = 1 + this.CalculateSize((BsonToken) bsonProperty.Name) + this.CalculateSize(bsonProperty.Value);
num1 += num2;
}
int num3 = num1 + 1;
bsonObject.CalculatedSize = num3;
return num3;
case BsonType.Array:
BsonArray bsonArray = (BsonArray) t;
int num4 = 4;
int i = 0;
foreach (BsonToken t1 in bsonArray)
{
++num4;
num4 += this.CalculateSize(MathUtils.IntLength(i));
num4 += this.CalculateSize(t1);
++i;
}
int num5 = num4 + 1;
bsonArray.CalculatedSize = num5;
return bsonArray.CalculatedSize;
case BsonType.Binary:
BsonValue bsonValue = (BsonValue) t;
byte[] numArray = (byte[]) bsonValue.Value;
bsonValue.CalculatedSize = 5 + numArray.Length;
return bsonValue.CalculatedSize;
case BsonType.Undefined:
case BsonType.Null:
return 0;
case BsonType.Oid:
return 12;
case BsonType.Boolean:
return 1;
case BsonType.Date:
return 8;
case BsonType.Regex:
BsonRegex bsonRegex = (BsonRegex) t;
int num6 = 0 + this.CalculateSize((BsonToken) bsonRegex.Pattern) + this.CalculateSize((BsonToken) bsonRegex.Options);
bsonRegex.CalculatedSize = num6;
return bsonRegex.CalculatedSize;
case BsonType.Integer:
return 4;
case BsonType.Long:
return 8;
default:
throw new ArgumentOutOfRangeException("t", StringUtils.FormatWith("Unexpected token when writing BSON: {0}", (IFormatProvider) CultureInfo.InvariantCulture, (object) t.Type));
}
}
示例13: RemoveParent
private void RemoveParent()
{
_parent = _parent.Parent;
}
示例14: RemoveParent
// Token: 0x0600015D RID: 349
// RVA: 0x00006A8A File Offset: 0x00004C8A
private void RemoveParent()
{
this._parent = this._parent.Parent;
}
示例15: WriteToken
public void WriteToken(BsonToken t)
{
CalculateSize(t);
WriteTokenInternal(t);
}