當前位置: 首頁>>代碼示例>>C#>>正文


C# BsonReader.ReadDouble方法代碼示例

本文整理匯總了C#中MongoDB.Bson.IO.BsonReader.ReadDouble方法的典型用法代碼示例。如果您正苦於以下問題:C# BsonReader.ReadDouble方法的具體用法?C# BsonReader.ReadDouble怎麽用?C# BsonReader.ReadDouble使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MongoDB.Bson.IO.BsonReader的用法示例。


在下文中一共展示了BsonReader.ReadDouble方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Deserialize

        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(double));
            var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);

            var bsonType = bsonReader.GetCurrentBsonType();
            switch (bsonType)
            {
                case BsonType.Double:
                    return bsonReader.ReadDouble();
                case BsonType.Int32:
                    return representationSerializationOptions.ToDouble(bsonReader.ReadInt32());
                case BsonType.Int64:
                    return representationSerializationOptions.ToDouble(bsonReader.ReadInt64());
                case BsonType.String:
                    return XmlConvert.ToDouble(bsonReader.ReadString());
                default:
                    var message = string.Format("Cannot deserialize Double from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
開發者ID:CloudMetal,項目名稱:mongo-csharp-driver,代碼行數:34,代碼來源:DoubleSerializer.cs

示例2: Deserialize

        public object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            object value = null;
            var valueType = actualType.GetConceptValueType();
			if (valueType == typeof(Guid)) {
				var guidBytes = new byte[16];
				BsonBinarySubType subType;
				bsonReader.ReadBinaryData (out guidBytes, out subType);
				value = new Guid (guidBytes);
			} else if (valueType == typeof(double))
				value = bsonReader.ReadDouble ();
			else if (valueType == typeof(float))
				value = (float)bsonReader.ReadDouble ();
			else if (valueType == typeof(Int32))
				value = bsonReader.ReadInt32 ();
			else if (valueType == typeof(Int64))
				value = bsonReader.ReadInt64 ();
			else if (valueType == typeof(bool))
				value = bsonReader.ReadBoolean ();
			else if (valueType == typeof(string))
				value = bsonReader.ReadString ();
			else if (valueType == typeof(decimal))
				value = decimal.Parse (bsonReader.ReadString ());
            
            var concept = ConceptFactory.CreateConceptInstance(actualType, value);
            return concept;
        }
開發者ID:jarlef,項目名稱:Bifrost,代碼行數:27,代碼來源:ConceptSerializer.cs

示例3: Deserialize

        public override object Deserialize(BsonReader bsonReader, System.Type nominalType, System.Type actualType, IBsonSerializationOptions options)
        {
            bsonReader.ReadStartDocument();

            var min     = ReadVector(bsonReader, "Min");
            var max     = ReadVector(bsonReader, "Max");
            var width   = bsonReader.ReadDouble("Width");
            var height  = bsonReader.ReadDouble("Height");

            bsonReader.ReadEndDocument();

            return new Rectangle(min, max);
        }
開發者ID:BernhardGlueck,項目名稱:Phare,代碼行數:13,代碼來源:RectangleBsonSerializer.cs

示例4: Deserialize

        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(bool));

            var bsonType = bsonReader.GetCurrentBsonType();
            switch (bsonType)
            {
                case BsonType.Boolean:
                    return bsonReader.ReadBoolean();
                case BsonType.Double:
                    return bsonReader.ReadDouble() != 0.0;
                case BsonType.Int32:
                    return bsonReader.ReadInt32() != 0;
                case BsonType.Int64:
                    return bsonReader.ReadInt64() != 0;
                case BsonType.Null:
                    bsonReader.ReadNull();
                    return false;
                case BsonType.String:
                    return XmlConvert.ToBoolean(bsonReader.ReadString().ToLower());
                default:
                    var message = string.Format("Cannot deserialize Boolean from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
開發者ID:ncipollina,項目名稱:mongo-csharp-driver,代碼行數:38,代碼來源:BsonPrimitiveSerializers.cs

示例5: Deserialize

        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(decimal));
            var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);

            var bsonType = bsonReader.GetCurrentBsonType();
            switch (bsonType)
            {
                case BsonType.Array:
                    var array = (BsonArray)BsonArraySerializer.Instance.Deserialize(bsonReader, typeof(BsonArray), null);
                    var bits = new int[4];
                    bits[0] = array[0].AsInt32;
                    bits[1] = array[1].AsInt32;
                    bits[2] = array[2].AsInt32;
                    bits[3] = array[3].AsInt32;
                    return new decimal(bits);
                case BsonType.Double:
                    return representationSerializationOptions.ToDecimal(bsonReader.ReadDouble());
                case BsonType.Int32:
                    return representationSerializationOptions.ToDecimal(bsonReader.ReadInt32());
                case BsonType.Int64:
                    return representationSerializationOptions.ToDecimal(bsonReader.ReadInt64());
                case BsonType.String:
                    return XmlConvert.ToDecimal(bsonReader.ReadString());
                default:
                    var message = string.Format("Cannot deserialize Decimal from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
開發者ID:CloudMetal,項目名稱:mongo-csharp-driver,代碼行數:42,代碼來源:DecimalSerializer.cs

示例6: Deserialize

        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(TimeSpan));

            // support RepresentationSerializationOptions for backward compatibility
            var representationSerializationOptions = options as RepresentationSerializationOptions;
            if (representationSerializationOptions != null)
            {
                options = new TimeSpanSerializationOptions(representationSerializationOptions.Representation);
            }
            var timeSpanSerializationOptions = EnsureSerializationOptions<TimeSpanSerializationOptions>(options);

            BsonType bsonType = bsonReader.GetCurrentBsonType();
            switch (bsonType)
            {
                case BsonType.Double:
                    return FromDouble(bsonReader.ReadDouble(), timeSpanSerializationOptions.Units);
                case BsonType.Int32:
                    return FromInt32(bsonReader.ReadInt32(), timeSpanSerializationOptions.Units);
                case BsonType.Int64:
                    return FromInt64(bsonReader.ReadInt64(), timeSpanSerializationOptions.Units);
                case BsonType.String:
                    return TimeSpan.Parse(bsonReader.ReadString()); // not XmlConvert.ToTimeSpan (we're using .NET's format for TimeSpan)
                default:
                    var message = string.Format("Cannot deserialize TimeSpan from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
開發者ID:robinNode,項目名稱:mongo-csharp-driver,代碼行數:41,代碼來源:TimeSpanSerializer.cs

示例7: Deserialize

        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>
        /// An object.
        /// </returns>
        public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            if (bsonReader.GetCurrentBsonType() == BsonType.Null)
            {
                bsonReader.ReadNull();
                return null;
            }
            else
            {
                bsonReader.ReadStartArray();
                var longitude = bsonReader.ReadDouble();
                var latitude = bsonReader.ReadDouble();
                bsonReader.ReadEndArray();

                return new GeoJson2DGeographicCoordinates(longitude, latitude);
            }
        }
開發者ID:einaregilsson,項目名稱:mongo-csharp-driver,代碼行數:28,代碼來源:GeoJson2DGeographicCoordinatesSerializer.cs

示例8: Deserialize

        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>
        /// An object.
        /// </returns>
        public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            if (bsonReader.GetCurrentBsonType() == BsonType.Null)
            {
                bsonReader.ReadNull();
                return null;
            }
            else
            {
                bsonReader.ReadStartArray();
                var easting = bsonReader.ReadDouble();
                var northing = bsonReader.ReadDouble();
                bsonReader.ReadEndArray();

                return new GeoJson2DProjectedCoordinates(easting, northing);
            }
        }
開發者ID:einaregilsson,項目名稱:mongo-csharp-driver,代碼行數:28,代碼來源:GeoJson2DProjectedCoordinatesSerializer.cs

示例9: Deserialize

        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>
        /// An object.
        /// </returns>
        public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            if (bsonReader.GetCurrentBsonType() == BsonType.Null)
            {
                bsonReader.ReadNull();
                return null;
            }
            else
            {
                bsonReader.ReadStartArray();
                var x = bsonReader.ReadDouble();
                var y = bsonReader.ReadDouble();
                var z = bsonReader.ReadDouble();
                bsonReader.ReadEndArray();

                return new GeoJson3DCoordinates(x, y, z);
            }
        }
開發者ID:einaregilsson,項目名稱:mongo-csharp-driver,代碼行數:29,代碼來源:GeoJson3DCoordinatesSerializer.cs

示例10: ReadNullableDouble

        protected double? ReadNullableDouble(BsonReader reader,string name)
        {
            reader.ReadName(name);

            var type = reader.GetCurrentBsonType();

            if ( type == BsonType.Null)
            {
                reader.ReadNull();
                return null;
            }

            return reader.ReadDouble();
        }
開發者ID:BernhardGlueck,項目名稱:Phare,代碼行數:14,代碼來源:MongoDbSerializerBase.cs

示例11: Deserialize

 // public methods
 /// <summary>
 /// Deserializes an object from a BsonReader.
 /// </summary>
 /// <param name="bsonReader">The BsonReader.</param>
 /// <param name="nominalType">The nominal type of the object.</param>
 /// <param name="actualType">The actual type of the object.</param>
 /// <param name="options">The serialization options.</param>
 /// <returns>An object.</returns>
 public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, // ignored
     IBsonSerializationOptions options)
 {
     VerifyDeserializeType(nominalType);
     var bsonType = bsonReader.GetCurrentBsonType();
     switch (bsonType)
     {
         case BsonType.Int32: return Enum.ToObject(nominalType, bsonReader.ReadInt32());
         case BsonType.Int64: return Enum.ToObject(nominalType, bsonReader.ReadInt64());
         case BsonType.Double: return Enum.ToObject(nominalType, (long)bsonReader.ReadDouble());
         case BsonType.String: return Enum.Parse(nominalType, bsonReader.ReadString());
         default:
             var message = string.Format("Cannot deserialize {0} from BsonType {1}.", nominalType.FullName, bsonType);
             throw new FileFormatException(message);
     }
 }
開發者ID:masukuma,項目名稱:Nimbus,代碼行數:25,代碼來源:EnumSerializer.cs

示例12: Deserialize

        // public methods
        /// <summary>
        /// Deserializes an object from a BsonReader.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="actualType">The actual type of the object.</param>
        /// <param name="options">The serialization options.</param>
        /// <returns>An object.</returns>
        public override object Deserialize(
            BsonReader bsonReader,
            Type nominalType,
            Type actualType,
            IBsonSerializationOptions options)
        {
            VerifyTypes(nominalType, actualType, typeof(BsonDouble));

            var bsonType = bsonReader.GetCurrentBsonType();
            switch (bsonType)
            {
                case BsonType.Double:
                    return new BsonDouble(bsonReader.ReadDouble());
                default:
                    var message = string.Format("Cannot deserialize BsonDouble from BsonType {0}.", bsonType);
                    throw new FileFormatException(message);
            }
        }
開發者ID:Khosrow-Azizi,項目名稱:MasterExperimentV2,代碼行數:27,代碼來源:BsonDoubleSerializer.cs

示例13: Deserialize

 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType
 )
 {
     switch (bsonReader.CurrentBsonType) {
         case BsonType.Boolean:
             return bsonReader.ReadBoolean();
         case BsonType.Double:
             return bsonReader.ReadDouble() != 0.0;
         case BsonType.Int32:
             return bsonReader.ReadInt32() != 0;
         case BsonType.Int64:
             return bsonReader.ReadInt64() != 0;
         case BsonType.Null:
             bsonReader.ReadNull();
             return false;
         case BsonType.String:
             return XmlConvert.ToBoolean(bsonReader.ReadString().ToLower());
         default:
             var message = string.Format("Cannot deserialize Boolean from BsonType: {0}", bsonReader.CurrentBsonType);
             throw new FileFormatException(message);
     }
 }
開發者ID:swiggin1,項目名稱:mongo-csharp-driver,代碼行數:24,代碼來源:BsonPrimitiveSerializers.cs

示例14: Deserialize

 /// <summary>
 /// Deserializes an object from a BsonReader.
 /// </summary>
 /// <param name="bsonReader">The BsonReader.</param>
 /// <param name="nominalType">The nominal type of the object.</param>
 /// <param name="options">The serialization options.</param>
 /// <returns>An object.</returns>
 public override object Deserialize(
     BsonReader bsonReader,
     Type nominalType,
     IBsonSerializationOptions options
 ) {
     var representationOptions = (RepresentationSerializationOptions) options ?? defaultRepresentationOptions;
     var bsonType = bsonReader.CurrentBsonType;
     switch (bsonType) {
         case BsonType.Array:
             var array = BsonArray.ReadFrom(bsonReader);
             var bits = new int[4];
             bits[0] = array[0].AsInt32;
             bits[1] = array[1].AsInt32;
             bits[2] = array[2].AsInt32;
             bits[3] = array[3].AsInt32;
             return new decimal(bits);
         case BsonType.Double:
             return representationOptions.ToDecimal(bsonReader.ReadDouble());
         case BsonType.Int32:
             return representationOptions.ToDecimal(bsonReader.ReadInt32());
         case BsonType.Int64:
             return representationOptions.ToDecimal(bsonReader.ReadInt64());
         case BsonType.String:
             return XmlConvert.ToDecimal(bsonReader.ReadString());
         default:
             var message = string.Format("Cannot deserialize Decimal from BsonType: {0}", bsonType);
             throw new FileFormatException(message);
     }
 }
開發者ID:ebix,項目名稱:mongo-csharp-driver,代碼行數:36,代碼來源:NetPrimitiveSerializers.cs

示例15: ReadObject

 //_120509_173140 keep consistent
 static object ReadObject(BsonReader bsonReader)
 {
     switch (bsonReader.GetCurrentBsonType())
     {
         case BsonType.Array: return ReadArray(bsonReader); // replacement
         case BsonType.Binary: var binary = BsonSerializer.Deserialize<BsonValue>(bsonReader); return BsonTypeMapper.MapToDotNetValue(binary) ?? binary; // byte[] or Guid else self
         case BsonType.Boolean: return bsonReader.ReadBoolean();
         case BsonType.DateTime: return BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(bsonReader.ReadDateTime());
         case BsonType.Document: return ReadCustomObject(bsonReader); // replacement
         case BsonType.Double: return bsonReader.ReadDouble();
         case BsonType.Int32: return bsonReader.ReadInt32();
         case BsonType.Int64: return bsonReader.ReadInt64();
         case BsonType.Null: bsonReader.ReadNull(); return null;
         case BsonType.ObjectId: return bsonReader.ReadObjectId();
         case BsonType.String: return bsonReader.ReadString();
         default: return BsonSerializer.Deserialize<BsonValue>(bsonReader);
     }
 }
開發者ID:nightroman,項目名稱:Mdbc,代碼行數:19,代碼來源:Serializer.cs


注:本文中的MongoDB.Bson.IO.BsonReader.ReadDouble方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。