JValue supports 32 bit integer with bson

Json.net supports Bson however JValue convert every integer value to int64 bit..

 

In bson. int32 need 4 bytes and int64 need 8 bytes...so there is a room to improve it.

 

find JValue.cs

 

 

add a new constructor

 

public JValue(int value)
        : this(value, JTokenType.Integer)
    { }

 

 

 

and then find

 

 

public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)

 

add some codes here:

 

case JTokenType.Integer:

+   if (this._value is int)
+              {
+                  writer.WriteValue(Convert.ToInt32(this._value, CultureInfo. InvariantCulture));
+              }
+              else
+              {
+                  writer.WriteValue(Convert.ToInt64(_value, CultureInfo.InvariantCulture));
+              }

 

 

build it..it should work fine with bson from now on.

 

你可能感兴趣的:(.net,C#,Mono)