2016-12-09 6 views

答えて

3

本当に完全な答えを出すための質問はありませんが、探している変更はmongoドキュメントのシリアル化の下で文書化されています。

http://mongodb.github.io/mongo-csharp-driver/2.4/reference/bson/serialization/#implementation-1

彼らは、基本クラスになりましタイプを取るということで最大の変更点。

ので

V1ドライバコード

public class IntegerCoercion : BsonBaseSerializer 
{ 
    public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) 
    { 
     if (bsonReader.CurrentBsonType == BsonType.Int32) 
     { 
      return bsonReader.ReadInt32(); 
     } 
     if (bsonReader.CurrentBsonType == BsonType.String) 
     { 
      var value = bsonReader.ReadString(); 
      if (string.IsNullOrWhiteSpace(value)) 
      { 
       return null; 
      } 
      return Convert.ToInt32(value); 
     } 
     bsonReader.SkipValue(); 
     return null; 
    } 

    public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options) 
    { 
     if (value == null) 
     { 
      bsonWriter.WriteNull(); 
      return; 
     } 
     bsonWriter.WriteInt32(Convert.ToInt32(value)); 
    } 
} 

V2ドライバコード

public class IntegerCoercion : SerializerBase<object> 
{ 
    public override object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) 
    { 
     if (context.Reader.CurrentBsonType == BsonType.Int32) 
     { 
      return context.Reader.ReadInt32(); 
     } 
     if (context.Reader.CurrentBsonType == BsonType.String) 
     { 
      var value = context.Reader.ReadString(); 
      if (string.IsNullOrWhiteSpace(value)) 
      { 
       return null; 
      } 
      return Convert.ToInt32(value); 
     } 
     context.Reader.SkipValue(); 
     return null; 
    } 

    public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value) 
    { 
     if (value == null) 
     { 
      context.Writer.WriteNull(); 
      return; 
     } 
     context.Writer.WriteInt32(Convert.ToInt32(value)); 
    } 
} 

ない大きな違いはなく、彼らは最小限だドライバーのほとんどの変更ととしてではなく壊れた

関連する問題