Skip to content

Commit d30739d

Browse files
committed
Fixed API for overloads
1 parent a8390d3 commit d30739d

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/MongoDB.Driver.Encryption/CsfleSchemaBuilder.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ public EncryptedCollectionBuilder<TDocument> EncryptMetadata(Guid? keyId = null,
9898
/// </summary>
9999
public EncryptedCollectionBuilder<TDocument> PatternProperty(
100100
string pattern,
101-
BsonType? bsonType = null,
101+
BsonType bsonType,
102102
EncryptionAlgorithm? algorithm = null,
103103
Guid? keyId = null)
104-
=> PatternProperty(pattern, bsonType is null? [] : [bsonType.Value], algorithm, keyId);
104+
=> PatternProperty(pattern, [bsonType], algorithm, keyId);
105105

106106
/// <summary>
107107
/// //TODO
@@ -145,10 +145,10 @@ public EncryptedCollectionBuilder<TDocument> PatternProperty<TField>(
145145
/// </summary>
146146
public EncryptedCollectionBuilder<TDocument> Property<TField>(
147147
Expression<Func<TDocument, TField>> path,
148-
BsonType? bsonType = null,
148+
BsonType bsonType,
149149
EncryptionAlgorithm? algorithm = null,
150150
Guid? keyId = null)
151-
=> Property(path, bsonType is null? null : [bsonType.Value], algorithm, keyId);
151+
=> Property(path, [bsonType], algorithm, keyId);
152152

153153
/// <summary>
154154
/// //TODO
@@ -165,10 +165,10 @@ public EncryptedCollectionBuilder<TDocument> Property<TField>(
165165
/// </summary>
166166
public EncryptedCollectionBuilder<TDocument> Property(
167167
FieldDefinition<TDocument> path,
168-
BsonType? bsonType = null,
168+
BsonType bsonType,
169169
EncryptionAlgorithm? algorithm = null,
170170
Guid? keyId = null)
171-
=> Property(path, bsonType is null? null : [bsonType.Value], algorithm, keyId);
171+
=> Property(path, [bsonType], algorithm, keyId);
172172

173173
/// <summary>
174174
/// //TODO
@@ -214,27 +214,27 @@ private static BsonDocument CreateEncryptDocument(
214214
EncryptionAlgorithm? algorithm = null,
215215
Guid? keyId = null)
216216
{
217-
if (bsonTypes == null)
217+
BsonValue bsonTypeVal = null;
218+
219+
if (bsonTypes != null)
218220
{
219-
throw new ArgumentNullException(nameof(bsonTypes));
220-
}
221+
var convertedBsonTypes = bsonTypes.Select(MapBsonTypeToString).ToList();
221222

222-
var convertedBsonTypes = bsonTypes.Select(MapBsonTypeToString).ToList();
223+
if (convertedBsonTypes.Count == 0)
224+
{
225+
throw new ArgumentException("At least one BSON type must be specified.", nameof(bsonTypes));
226+
}
223227

224-
if (convertedBsonTypes.Count == 0)
225-
{
226-
throw new ArgumentException("At least one BSON type must be specified.", nameof(bsonTypes));
228+
bsonTypeVal = convertedBsonTypes.Count == 1
229+
? convertedBsonTypes[0]
230+
: new BsonArray(convertedBsonTypes);
227231
}
228232

229-
BsonValue bsonTypeVal = convertedBsonTypes.Count == 1
230-
? convertedBsonTypes[0]
231-
: new BsonArray(convertedBsonTypes);
232-
233233
return new BsonDocument
234234
{
235235
{ "encrypt", new BsonDocument
236236
{
237-
{ "bsonType", bsonTypeVal },
237+
{ "bsonType", () => bsonTypeVal, bsonTypeVal is not null },
238238
{ "algorithm", () => MapCsfleEncyptionAlgorithmToString(algorithm!.Value), algorithm is not null },
239239
{
240240
"keyId",

0 commit comments

Comments
 (0)