-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5552: Add support for $convert in LINQ #1659
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
Merged
Merged
Changes from all commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
b11abcb
Small correction
papafe e51d733
Improvements
papafe 7484967
Fixed errors
papafe d604e2a
Small rename
papafe e46ebc6
Various corrections
papafe 9ff2347
Behaviour correction
papafe 3d55596
Simplified code
papafe ebe1bf5
Small improvements
papafe 20763ce
Added test
papafe 64b0082
Several improvements
papafe be829c9
Added int tests
papafe 4007671
Added convertToLong tests
papafe 9b40d91
Small corrections
papafe 9e6c11a
Various fixes
papafe f1cc942
Small corrections
papafe 6b3fb54
Fixed docs
papafe f25e15b
Fixed docs
papafe 73fe700
Added byteOrder, removed format where not necessary
papafe 94651f8
Small fix
papafe 82b3f02
Imrpoved tests
papafe 6bfc029
Added tests
papafe 23556b3
Fixed test
papafe 76dd221
Various fixes
papafe 6b6be70
Naming correction
papafe 311832d
Small naming correction
papafe 34ef476
Small corrections
papafe 5f1732f
Fixes according to PR
papafe b17c354
Moved byteOrder to outer scope
papafe 37ab91e
Changed order
papafe 54395c1
Improved testing
papafe 5e5701e
Rename
papafe 2b16ebb
Corrected name of feature
papafe 40276ed
Small corrections
papafe 16887f9
Added convert options
papafe c95d8a8
Added remark
papafe 8c4dbf8
Added missing methods
papafe 22691b4
Added missing methods
papafe cfff9b3
Various corrections
papafe a341cfe
Various corrections
papafe 16ec0b1
Improvements
papafe 698690f
TestMethod renaming
papafe 10f05e6
Improved methods
papafe 98fd0e1
Other improvements
papafe 021f4f0
Almost finished tests
papafe d7bca77
Added more tests
papafe f94891c
Small corrections
papafe 0664eb1
Small fix
papafe e4c185b
Corrected name
papafe 3af159e
Various fixes according to PR
papafe 23ddc74
Moving to a simple convert method
papafe 6829b66
Small correction
papafe b237d0d
Test improvement
papafe 555bbd9
Added tests
papafe fd9626c
Nits correction
papafe 403c02a
Nit corrections
papafe 69cf61b
Imrpoved
papafe 8e8eea5
Small fix
papafe 6e87398
Tried to move stuff to simplifier
papafe fb5509e
Small fixes
papafe 3ee0f42
Removed extra line
papafe 705f5b3
Added missing copyright
papafe 2a0829b
Restored simplification
papafe 53b886a
Various fixes
papafe 37cb373
added more tests
papafe 9b88903
Small rename
papafe 5fa5850
Reordered tests
papafe 03c3974
Slight improvements
papafe 9aeabb3
Small fix
papafe 07de4e5
Removed constraints
papafe 39904d0
Tried to add new tests
papafe e4fc2a7
Added generic convert test
papafe dc2841e
Small fix
papafe 276434d
Small fixes
papafe 23de869
Fixes according to PR
papafe d844cd2
Corrections
papafe ec52d7f
Small corrections
papafe f8a5a66
Added test
papafe abda353
Removed unused
papafe e2f2f6a
Restored files
papafe afa7bdd
Small fixes
papafe de05dd6
Small corrections + test fix
papafe 3b19233
Small naming correction
papafe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* 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 MongoDB.Bson; | ||
|
||
namespace MongoDB.Driver | ||
{ | ||
/// <summary> | ||
/// Represents the options parameter for <see cref="Mql.Convert{TFrom, TTo}(TFrom, ConvertOptions{TTo})"/>. | ||
/// </summary> | ||
public abstract class ConvertOptions | ||
{ | ||
private ByteOrder? _byteOrder; | ||
private string _format; | ||
private BsonBinarySubType? _subType; | ||
|
||
/// <summary> | ||
/// The byteOrder parameter. | ||
/// </summary> | ||
public ByteOrder? ByteOrder | ||
{ | ||
get => _byteOrder; | ||
set => _byteOrder = value; | ||
} | ||
|
||
/// <summary> | ||
/// The format parameter. | ||
/// </summary> | ||
public string Format | ||
{ | ||
get => _format; | ||
set => _format = value; | ||
} | ||
|
||
/// <summary> | ||
/// The subType parameter. | ||
/// </summary> | ||
public BsonBinarySubType? SubType | ||
{ | ||
get => _subType; | ||
set => _subType = value; | ||
} | ||
|
||
internal abstract bool OnErrorWasSet(out object onError); | ||
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. Should it be named 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 think it would make sense. |
||
|
||
internal abstract bool OnNullWasSet(out object onNull); | ||
} | ||
|
||
/// <summary> | ||
/// Represents the options parameter for <see cref="Mql.Convert{TFrom, TTo}(TFrom, ConvertOptions{TTo})"/>. | ||
/// This class allows to set 'onError' and 'onNull'. | ||
/// </summary> | ||
/// <typeparam name="TTo"> The type of 'onError' and 'onNull'.</typeparam> | ||
public class ConvertOptions<TTo> : ConvertOptions | ||
{ | ||
private TTo _onError; | ||
private bool _onErrorWasSet; | ||
private TTo _onNull; | ||
private bool _onNullWasSet; | ||
|
||
/// <summary> | ||
/// The onError parameter. | ||
/// </summary> | ||
public TTo OnError | ||
{ | ||
get => _onError; | ||
set | ||
{ | ||
_onError = value; | ||
_onErrorWasSet = true; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The onNull parameter. | ||
/// </summary> | ||
public TTo OnNull | ||
{ | ||
get => _onNull; | ||
set | ||
{ | ||
_onNull = value; | ||
_onNullWasSet = true; | ||
} | ||
} | ||
|
||
internal override bool OnErrorWasSet(out object onError) | ||
{ | ||
onError = _onError; | ||
return _onErrorWasSet; | ||
} | ||
|
||
internal override bool OnNullWasSet(out object onNull) | ||
{ | ||
onNull = _onNull; | ||
return _onNullWasSet; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Represents the byte order of binary data when converting to/from numerical types using <see cref="Mql.Convert{TFrom, TTo}(TFrom, ConvertOptions{TTo})"/>. | ||
/// </summary> | ||
public enum ByteOrder | ||
{ | ||
/// <summary> | ||
/// Big endian order. | ||
/// </summary> | ||
BigEndian, | ||
/// <summary> | ||
/// Little endian order. | ||
/// </summary> | ||
LittleEndian, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstEnumExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* 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; | ||
using MongoDB.Bson; | ||
|
||
namespace MongoDB.Driver.Linq.Linq3Implementation.Ast | ||
{ | ||
internal static class AstEnumExtensions | ||
{ | ||
public static string Render(this BsonType type) | ||
{ | ||
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)) | ||
}; | ||
} | ||
|
||
public static string Render(this ByteOrder byteOrder) | ||
{ | ||
return byteOrder switch | ||
{ | ||
ByteOrder.BigEndian => "big", | ||
ByteOrder.LittleEndian => "little", | ||
_ => throw new ArgumentException($"Unexpected {nameof(ByteOrder)}: {byteOrder}.", nameof(byteOrder)) | ||
}; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.