diff --git a/LiteDB/Document/BsonValue.cs b/LiteDB/Document/BsonValue.cs index 16618b125..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; @@ -61,6 +61,14 @@ public BsonValue(Int64 value) this.Type = BsonType.Int64; this.RawValue = value; } + + public BsonValue(UInt32 value) : this((Int64)value) + { + } + + public BsonValue(UInt64 value) : this((Double)value) + { + } public BsonValue(Double value) { @@ -260,6 +268,17 @@ 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 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); } @@ -385,6 +404,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) { @@ -421,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