コード例 #1
0
        public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            BsonReader bsonReader = (BsonReader)context.Reader;

            CalendarWrapper item = new CalendarWrapper();

            bsonReader.ReadStartDocument();
            item.Name = bsonReader.ReadString(ID);
            var binaryData = bsonReader.ReadBinaryData(CONTENT_STREAM);
            item.Calendar = (ICalendar)new BinaryFormatter().Deserialize(new MemoryStream(binaryData.Bytes));
            bsonReader.ReadEndDocument();

            return item;
        }
コード例 #2
0
        public override bool Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            IBsonReader bsonReader = context.Reader;

            BsonType bsonType = bsonReader.GetCurrentBsonType();
            if (bsonType == BsonType.String)
            {
                string token = bsonReader.ReadString();
                return ParseBoolean.FromString(token);
            }
            else
            {
                return base.Deserialize(context, args);
            }
        }
コード例 #3
0
 public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     var bsonType = context.Reader.CurrentBsonType;
     switch (bsonType)
     {
         case BsonType.Null:
             context.Reader.ReadNull();
             return null;
         case BsonType.String:
             return context.Reader.ReadString();
         case BsonType.Int32:
             return context.Reader.ReadInt32().ToString();
         default:
             var message = string.Format("ZipCodeSerializer expects to find a String or an Int32, not a {0}.", bsonType);
             throw new BsonSerializationException(message);
     }
 }
        public object Deserialize( BsonDeserializationContext context, BsonDeserializationArgs args )
        {
            var bsonReader = context.Reader;
            BsonType bsonType = bsonReader.CurrentBsonType;

            object result;

            if( bsonType == BsonType.Null )
            {
                bsonReader.ReadNull();
                result = null;
            }
            else
            {
                if( bsonType == BsonType.Document )
                {
                    var dictionary = new DynamicDictionary();

                    bsonReader.ReadStartDocument();

                    IDiscriminatorConvention valueDiscriminatorConvention = BsonSerializer.LookupDiscriminatorConvention( typeof( object ) );

                    while( bsonReader.ReadBsonType() != BsonType.EndOfDocument )
                    {
                        string key = bsonReader.ReadName();
                        Type valueType = valueDiscriminatorConvention.GetActualType( bsonReader, typeof( object ) );
                        IBsonSerializer valueSerializer = BsonSerializer.LookupSerializer( valueType );
                        object value = valueSerializer.Deserialize( context );

                        if( key != "_t" )
                        {
                            dictionary.Add( key.Replace( '\x03', '.' ), value );
                        }
                    }
                    bsonReader.ReadEndDocument();
                    result = dictionary;
                }
                else
                {
                    string message = string.Format( "Can't deserialize a {0} from BsonType {1}.", context.Reader.CurrentBsonType, bsonType );
                    throw new BsonException( message );
                }
            }

            return result;
        }
コード例 #5
0
            public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
            {
                var bsonType = context.Reader.CurrentBsonType;
                switch (bsonType)
                {
                    case BsonType.Null:
                        context.Reader.ReadNull();
                        return null;

                    case BsonType.String:
                        var value = context.Reader.ReadString();
                        if (!string.IsNullOrEmpty(value))
                        {
                            value = string.Concat(char.ToUpperInvariant(value[0]), value.Substring(1));
                            var enumValue = Enum.Parse(ValueType, value);
                            return enumValue;
                        }
                        return value;

                    default:
                        return baseSerializer.Deserialize(context, args);
                }
            }
コード例 #6
0
        object IBsonSerializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var response = GenerateJToken(context.Reader, null);

            return(response);
        }
コード例 #7
0
 public JToken Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     return(GenerateJToken(context.Reader, null));
 }
コード例 #8
0
        /// <summary>
        /// The Deserialize function.
        /// </summary>
        /// <param name="context">The context parameter.</param>
        /// <param name="args">The arguments parameter.</param>
        /// <returns>The result of the deserialization of the element.</returns>
        public override List <ClientAddressDto> Deserialize(MongoDB.Bson.Serialization.BsonDeserializationContext context, MongoDB.Bson.Serialization.BsonDeserializationArgs args)
        {
            context?.Reader.ReadStartArray();

            var result = new List <ClientAddressDto>();

            while (true)
            {
                try
                {
                    // this catch block only need to identify the end of the Array
                    context.Reader.ReadStartDocument();
                }
                catch (Exception)
                {
                    context.Reader.ReadEndArray();
                    break;
                }

                var street     = context.Reader.ReadString();
                var number     = context.Reader.ReadString();
                var postalCode = context.Reader.ReadString();

                result.Add(new ClientAddressDto(street, number, postalCode));

                context.Reader.ReadEndDocument();
            }

            return(result);
        }
コード例 #9
0
ファイル: MongoDatabase.cs プロジェクト: teledu/MoManI
 public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     return Enum.Parse(ValueType, context.Reader.ReadString());
 }
コード例 #10
0
 public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
 public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
 {
     var key = context.Reader.ReadString();
     var gr = GrainReference.FromKeyString(key);
     return gr;
 }