-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5453: Add builder for CSFLE schemas #1631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
db1dea7
cee7a93
7d1c109
87b1c2f
ee898d3
a3a06a7
e599cc0
400b8b0
0a32d51
c3bfde4
dd1aeaf
f21b87a
f88465c
33fcbeb
6a265c2
c37c6bb
6f1b2a3
4942f97
93f46f9
670c663
517db94
8f10903
ef5faa9
601169e
4ddfdf8
f31c705
0069760
bd88e8b
20379df
a8390d3
d30739d
fa3143c
134622e
6098c29
7a4f46a
a25ad56
84ddfbd
eca0ace
b6ef4d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* Copyright 2010-present MongoDB Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using System; | ||
|
||
namespace MongoDB.Bson.Serialization | ||
{ | ||
/// <summary> | ||
/// A static class containing extension methods for <see cref="BsonType"/>. | ||
/// </summary> | ||
public static class BsonTypeExtensions | ||
{ | ||
/// <summary> | ||
/// Maps a <see cref="BsonType"/> to its corresponding string representation. | ||
/// </summary> | ||
/// <param name="type">The input type to map.</param> | ||
public static string ToStringRepresentation(this BsonType type) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rstam this is the new method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we should add this to the public API just so EF Core can use it. EF Core can easily duplicate this very small method. Unless there is a clear scenario where a USER would find this useful, I wouldn't add it to the public API. Definitely a good idea to centralize this conversion in an If we do make this public I suggest it be done as a separate JIRA ticket so that users can see it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a useful method with a clear and defined purpose and limited API surface. If I need it in the EF provider chances are other people need it too and probably also had to reproduce it. They'd need it right now if they're doing their own queryable encryption or CSFLE work and are trying to leverage BsonType in order to generate the schema. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rstam What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not really. They would just use the string constants directly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is not just ANY string representation, this is the string representation the SERVER uses. If we are going to add this to the public API (which I think is questionable) maybe a better name is called for, something like I don't know why you chose |
||
{ | ||
return type switch | ||
{ | ||
BsonType.Array => "array", | ||
BsonType.Binary => "binData", | ||
BsonType.Boolean => "bool", | ||
BsonType.DateTime => "date", | ||
BsonType.Decimal128 => "decimal", | ||
BsonType.Document => "object", | ||
BsonType.Double => "double", | ||
BsonType.Int32 => "int", | ||
BsonType.Int64 => "long", | ||
BsonType.JavaScript => "javascript", | ||
BsonType.JavaScriptWithScope => "javascriptWithScope", | ||
BsonType.MaxKey => "maxKey", | ||
BsonType.MinKey => "minKey", | ||
BsonType.Null => "null", | ||
BsonType.ObjectId => "objectId", | ||
BsonType.RegularExpression => "regex", | ||
BsonType.String => "string", | ||
BsonType.Symbol => "symbol", | ||
BsonType.Timestamp => "timestamp", | ||
BsonType.Undefined => "undefined", | ||
_ => throw new ArgumentException($"Unexpected BSON type: {type}.", nameof(type)) | ||
}; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I'm not convinced we should add this class, if we do add it, I think this is the wrong location.
I would put it in the
ObjectModel
folder right next to theBsonType.cs
file.