Skip to content

Commit ed93b64

Browse files
committed
CSHARP-527: Custom Gt/Gte/Lt/Lte filter builders for unsigned integer fields represented using signed integers.
1 parent 2ecfe93 commit ed93b64

File tree

3 files changed

+871
-4
lines changed

3 files changed

+871
-4
lines changed

src/MongoDB.Bson/Serialization/IBsonSerializerExtensions.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2010-2015 MongoDB Inc.
1+
/* Copyright 2010-2016 MongoDB Inc.
22
*
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
@@ -14,6 +14,7 @@
1414
*/
1515

1616
using System;
17+
using MongoDB.Bson.IO;
1718

1819
namespace MongoDB.Bson.Serialization
1920
{
@@ -72,5 +73,26 @@ public static void Serialize<TValue>(this IBsonSerializer<TValue> serializer, Bs
7273
var args = new BsonSerializationArgs { NominalType = serializer.ValueType };
7374
serializer.Serialize(context, args, value);
7475
}
76+
77+
/// <summary>
78+
/// Converts a value to a BsonValue by serializing it.
79+
/// </summary>
80+
/// <typeparam name="TValue">The type of the value.</typeparam>
81+
/// <param name="serializer">The serializer.</param>
82+
/// <param name="value">The value.</param>
83+
/// <returns>The serialized value.</returns>
84+
public static BsonValue ToBsonValue<TValue>(this IBsonSerializer<TValue> serializer, TValue value)
85+
{
86+
var document = new BsonDocument();
87+
using (var writer = new BsonDocumentWriter(document))
88+
{
89+
var context = BsonSerializationContext.CreateRoot(writer);
90+
writer.WriteStartDocument();
91+
writer.WriteName("x");
92+
serializer.Serialize(context, value);
93+
writer.WriteEndDocument();
94+
}
95+
return document[0];
96+
}
7597
}
7698
}

0 commit comments

Comments
 (0)