From 3b73c3c7a8a09264f740f87fc69cbea854b02c4d Mon Sep 17 00:00:00 2001 From: s_falahati Date: Mon, 20 May 2019 20:13:55 +0430 Subject: [PATCH 1/2] Support added for `UInt32` --- LiteDB/Document/BsonValue.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/LiteDB/Document/BsonValue.cs b/LiteDB/Document/BsonValue.cs index 16618b125..28d75d776 100644 --- a/LiteDB/Document/BsonValue.cs +++ b/LiteDB/Document/BsonValue.cs @@ -61,6 +61,10 @@ public BsonValue(Int64 value) this.Type = BsonType.Int64; this.RawValue = value; } + + public BsonValue(UInt32 value) : this((Int64)value) + { + } public BsonValue(Double value) { @@ -260,6 +264,11 @@ public long AsInt64 get { return this.IsNumber ? Convert.ToInt64(this.RawValue) : default(Int64); } } + public uint AsUInt32 + { + get { return this.IsNumber ? Convert.ToUInt32(this.RawValue) : default(UInt32); } + } + public double AsDouble { get { return this.IsNumber ? Convert.ToDouble(this.RawValue) : default(Double); } @@ -385,6 +394,18 @@ public static implicit operator BsonValue(Int32 value) return new BsonValue(value); } + // UInt32 + public static implicit operator UInt32(BsonValue value) + { + return (UInt32)value.RawValue; + } + + // UInt32 + public static implicit operator BsonValue(UInt32 value) + { + return new BsonValue(value); + } + // Int64 public static implicit operator Int64(BsonValue value) { From 5642e771a77a146d59dd06457b2e190caa5d68d3 Mon Sep 17 00:00:00 2001 From: s_falahati Date: Mon, 20 May 2019 20:14:16 +0430 Subject: [PATCH 2/2] Support for `UInt64` improved. --- LiteDB/Document/BsonValue.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/LiteDB/Document/BsonValue.cs b/LiteDB/Document/BsonValue.cs index 28d75d776..e4183485f 100644 --- a/LiteDB/Document/BsonValue.cs +++ b/LiteDB/Document/BsonValue.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Text; @@ -66,6 +66,10 @@ public BsonValue(UInt32 value) : this((Int64)value) { } + public BsonValue(UInt64 value) : this((Double)value) + { + } + public BsonValue(Double value) { this.Type = BsonType.Double; @@ -269,6 +273,12 @@ public uint AsUInt32 get { return this.IsNumber ? Convert.ToUInt32(this.RawValue) : default(UInt32); } } + public ulong AsUInt64 + { + get { return this.IsNumber ? Convert.ToUInt64(this.RawValue) : default(UInt64); } + } + + public double AsDouble { get { return this.IsNumber ? Convert.ToDouble(this.RawValue) : default(Double); } @@ -442,16 +452,16 @@ public static implicit operator BsonValue(Decimal value) return new BsonValue(value); } - // UInt64 (to avoid ambigous between Double-Decimal) + // UInt64 (to avoid ambiguous between Double-Decimal) public static implicit operator UInt64(BsonValue value) { return (UInt64)value.RawValue; } - // Decimal + // UInt64 public static implicit operator BsonValue(UInt64 value) { - return new BsonValue((Double)value); + return new BsonValue(value); } // String