-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename Cosmos MethodCallTranslators. Support multiple RegexOptions
- Loading branch information
Showing
8 changed files
with
237 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
162 changes: 162 additions & 0 deletions
162
src/EFCore.Cosmos/Query/Internal/SqlRegexMatchExpression.cs
This file contains 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,162 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Text.RegularExpressions; | ||
using Microsoft.EntityFrameworkCore.Cosmos.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public class SqlRegexMatchExpression : SqlExpression, IEquatable<SqlRegexMatchExpression> | ||
{ | ||
private static readonly ISet<RegexOptions> AllowedOptions = new HashSet<RegexOptions> | ||
{ | ||
RegexOptions.None, | ||
RegexOptions.IgnoreCase, | ||
RegexOptions.Multiline, | ||
RegexOptions.Singleline, | ||
RegexOptions.IgnorePatternWhitespace | ||
}; | ||
|
||
private static RegexOptions VerifyOptions(RegexOptions optionType) | ||
=> AllowedOptions.Contains(optionType) | ||
? optionType | ||
: throw new InvalidOperationException( | ||
CosmosStrings.UnsupportedOperatorForSqlExpression( | ||
optionType, typeof(SqlRegexMatchExpression).ShortDisplayName())); | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public SqlRegexMatchExpression( | ||
SqlExpression match, | ||
SqlExpression pattern, | ||
RegexOptions options, | ||
CoreTypeMapping? typeMapping) | ||
: base(typeof(bool), typeMapping) | ||
{ | ||
Match = match; | ||
Pattern = pattern; | ||
|
||
Options = VerifyOptions(options); | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public virtual SqlExpression Match { get; } | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public virtual SqlExpression Pattern { get; } | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public virtual RegexOptions Options { get; } | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
protected override Expression VisitChildren(ExpressionVisitor visitor) | ||
=> Update((SqlExpression)visitor.Visit(Match), (SqlExpression)visitor.Visit(Pattern)); | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public virtual SqlRegexMatchExpression Update(SqlExpression match, SqlExpression pattern) | ||
=> match != Match || pattern != Pattern | ||
? new SqlRegexMatchExpression(match, pattern, Options, TypeMapping) | ||
: this; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public virtual bool Equals(SqlRegexMatchExpression? other) | ||
=> ReferenceEquals(this, other) | ||
|| other is not null | ||
&& base.Equals(other) | ||
&& Match.Equals(other.Match) | ||
&& Pattern.Equals(other.Pattern) | ||
&& Options.Equals(other.Options); | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public override bool Equals(object? other) | ||
=> other is SqlRegexMatchExpression otherRegexMatch && Equals(otherRegexMatch); | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public override int GetHashCode() | ||
=> HashCode.Combine(base.GetHashCode(), Match, Pattern, Options); | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
protected override void Print(ExpressionPrinter expressionPrinter) | ||
{ | ||
expressionPrinter.Append("RegexMatch("); | ||
expressionPrinter.Visit(Match); | ||
expressionPrinter.Append(", "); | ||
expressionPrinter.Visit(Pattern); | ||
expressionPrinter.Append(", "); | ||
|
||
var option = Options switch | ||
{ | ||
RegexOptions.Multiline => "m", | ||
RegexOptions.Singleline => "s", | ||
RegexOptions.IgnoreCase => "i", | ||
RegexOptions.IgnorePatternWhitespace => "x", | ||
_ => "" | ||
}; | ||
|
||
expressionPrinter.Append(option); | ||
expressionPrinter.Append(")"); | ||
} | ||
|
||
///// <summary> | ||
///// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
///// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
///// any release. You should only use it directly in your code with extreme caution and knowing that | ||
///// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
///// </summary> | ||
//public override string ToString() => $"RegexMatch({Match}, {Pattern}, {Options})"; | ||
} |
Oops, something went wrong.