Skip to content

Commit 60ebc8c

Browse files
authored
CSHARP-5453: Add builder for CSFLE schemas (#1631)
1 parent ba628c3 commit 60ebc8c

File tree

7 files changed

+1116
-59
lines changed

7 files changed

+1116
-59
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* Copyright 2010-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
18+
namespace MongoDB.Bson
19+
{
20+
/// <summary>
21+
/// A static class containing extension methods for <see cref="BsonType"/>.
22+
/// </summary>
23+
public static class BsonTypeExtensions
24+
{
25+
/// <summary>
26+
/// Maps a <see cref="BsonType"/> to its corresponding server string representation.
27+
/// </summary>
28+
/// <param name="type">The input type to map.</param>
29+
public static string ToServerString(this BsonType type)
30+
{
31+
return type switch
32+
{
33+
BsonType.Array => "array",
34+
BsonType.Binary => "binData",
35+
BsonType.Boolean => "bool",
36+
BsonType.DateTime => "date",
37+
BsonType.Decimal128 => "decimal",
38+
BsonType.Document => "object",
39+
BsonType.Double => "double",
40+
BsonType.Int32 => "int",
41+
BsonType.Int64 => "long",
42+
BsonType.JavaScript => "javascript",
43+
BsonType.JavaScriptWithScope => "javascriptWithScope",
44+
BsonType.MaxKey => "maxKey",
45+
BsonType.MinKey => "minKey",
46+
BsonType.Null => "null",
47+
BsonType.ObjectId => "objectId",
48+
BsonType.RegularExpression => "regex",
49+
BsonType.String => "string",
50+
BsonType.Symbol => "symbol",
51+
BsonType.Timestamp => "timestamp",
52+
BsonType.Undefined => "undefined",
53+
_ => throw new ArgumentException($"Unexpected BSON type: {type}.", nameof(type))
54+
};
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)