@@ -98,10 +98,10 @@ public EncryptedCollectionBuilder<TDocument> EncryptMetadata(Guid? keyId = null,
98
98
/// </summary>
99
99
public EncryptedCollectionBuilder < TDocument > PatternProperty (
100
100
string pattern ,
101
- BsonType ? bsonType = null ,
101
+ BsonType bsonType ,
102
102
EncryptionAlgorithm ? algorithm = null ,
103
103
Guid ? keyId = null )
104
- => PatternProperty ( pattern , bsonType is null ? [ ] : [ bsonType . Value ] , algorithm , keyId ) ;
104
+ => PatternProperty ( pattern , [ bsonType ] , algorithm , keyId ) ;
105
105
106
106
/// <summary>
107
107
/// //TODO
@@ -145,10 +145,10 @@ public EncryptedCollectionBuilder<TDocument> PatternProperty<TField>(
145
145
/// </summary>
146
146
public EncryptedCollectionBuilder < TDocument > Property < TField > (
147
147
Expression < Func < TDocument , TField > > path ,
148
- BsonType ? bsonType = null ,
148
+ BsonType bsonType ,
149
149
EncryptionAlgorithm ? algorithm = null ,
150
150
Guid ? keyId = null )
151
- => Property ( path , bsonType is null ? null : [ bsonType . Value ] , algorithm , keyId ) ;
151
+ => Property ( path , [ bsonType ] , algorithm , keyId ) ;
152
152
153
153
/// <summary>
154
154
/// //TODO
@@ -165,10 +165,10 @@ public EncryptedCollectionBuilder<TDocument> Property<TField>(
165
165
/// </summary>
166
166
public EncryptedCollectionBuilder < TDocument > Property (
167
167
FieldDefinition < TDocument > path ,
168
- BsonType ? bsonType = null ,
168
+ BsonType bsonType ,
169
169
EncryptionAlgorithm ? algorithm = null ,
170
170
Guid ? keyId = null )
171
- => Property ( path , bsonType is null ? null : [ bsonType . Value ] , algorithm , keyId ) ;
171
+ => Property ( path , [ bsonType ] , algorithm , keyId ) ;
172
172
173
173
/// <summary>
174
174
/// //TODO
@@ -214,27 +214,27 @@ private static BsonDocument CreateEncryptDocument(
214
214
EncryptionAlgorithm ? algorithm = null ,
215
215
Guid ? keyId = null )
216
216
{
217
- if ( bsonTypes == null )
217
+ BsonValue bsonTypeVal = null ;
218
+
219
+ if ( bsonTypes != null )
218
220
{
219
- throw new ArgumentNullException ( nameof ( bsonTypes ) ) ;
220
- }
221
+ var convertedBsonTypes = bsonTypes . Select ( MapBsonTypeToString ) . ToList ( ) ;
221
222
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
+ }
223
227
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 ) ;
227
231
}
228
232
229
- BsonValue bsonTypeVal = convertedBsonTypes . Count == 1
230
- ? convertedBsonTypes [ 0 ]
231
- : new BsonArray ( convertedBsonTypes ) ;
232
-
233
233
return new BsonDocument
234
234
{
235
235
{ "encrypt" , new BsonDocument
236
236
{
237
- { "bsonType" , bsonTypeVal } ,
237
+ { "bsonType" , ( ) => bsonTypeVal , bsonTypeVal is not null } ,
238
238
{ "algorithm" , ( ) => MapCsfleEncyptionAlgorithmToString ( algorithm ! . Value ) , algorithm is not null } ,
239
239
{
240
240
"keyId" ,
0 commit comments