Skip to content

Commit

Permalink
Addressing API review feedback (#34321)
Browse files Browse the repository at this point in the history
Change ReplacingExpressionVisitor.Replace to IReadOnlyList<Expression> parameters
Make ReaderColumn.GetFieldValueExpression and the new constructor experimental.
Make ReaderColumn.Create experimental.
Make ReaderColumn<T> constructor experimental.
  • Loading branch information
maumar authored Jul 31, 2024
1 parent 390b5b0 commit b25cba7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,9 @@ private static readonly MethodInfo Utf8GetBytesMethod
.Where(x => x.prms.Count() == 1 && x.prms[0].ParameterType.IsArray)
.Single().x.MakeGenericMethod(typeof(byte));

private static readonly MethodInfo Utf8JsonReaderTrySkipMethod
= typeof(Utf8JsonReader).GetMethod(nameof(Utf8JsonReader.TrySkip), [])!;

private static readonly PropertyInfo Utf8JsonReaderTokenTypeProperty
= typeof(Utf8JsonReader).GetProperty(nameof(Utf8JsonReader.TokenType))!;

private static readonly MethodInfo Utf8JsonReaderGetStringMethod
= typeof(Utf8JsonReader).GetMethod(nameof(Utf8JsonReader.GetString), [])!;

private static readonly MethodInfo EnumParseMethodInfo
= typeof(Enum).GetMethod(nameof(Enum.Parse), [typeof(Type), typeof(string)])!;

private static readonly MethodInfo ReadColumnCreateMethod
= typeof(ReaderColumn).GetMethod(nameof(ReaderColumn.Create))!;

private readonly static MethodInfo PropertyGetJsonValueReaderWriterMethod =
typeof(IReadOnlyProperty).GetMethod(nameof(IReadOnlyProperty.GetJsonValueReaderWriter), [])!;

Expand Down
4 changes: 4 additions & 0 deletions src/EFCore.Relational/Storage/ReaderColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.EntityFrameworkCore.Storage;

Expand Down Expand Up @@ -30,6 +31,7 @@ public abstract class ReaderColumn
/// <param name="name">The name of the column.</param>
/// <param name="property">The property being read if any, null otherwise.</param>
/// <param name="getFieldValueExpression">A lambda expression to get field value for the column from the reader.</param>
[Experimental(EFDiagnostics.PrecompiledQueryExperimental)]
protected ReaderColumn(Type type, bool nullable, string? name, IPropertyBase? property, LambdaExpression getFieldValueExpression)
{
Type = type;
Expand Down Expand Up @@ -62,6 +64,7 @@ protected ReaderColumn(Type type, bool nullable, string? name, IPropertyBase? pr
/// <summary>
/// A lambda expression to get field value for the column from the reader.
/// </summary>
[Experimental(EFDiagnostics.PrecompiledQueryExperimental)]
public virtual LambdaExpression GetFieldValueExpression { get; }

/// <summary>
Expand All @@ -75,6 +78,7 @@ protected ReaderColumn(Type type, bool nullable, string? name, IPropertyBase? pr
/// A <see cref="T:System.Func{DbDataReader, Int32[], T}" /> used to get the field value for this column.
/// </param>
/// <returns>An instance of <see cref="ReaderColumn{T}" />.</returns>
[Experimental(EFDiagnostics.PrecompiledQueryExperimental)]
public static ReaderColumn Create(
Type type,
bool nullable,
Expand Down
3 changes: 3 additions & 0 deletions src/EFCore.Relational/Storage/ReaderColumn`.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;

namespace Microsoft.EntityFrameworkCore.Storage;

/// <summary>
Expand All @@ -25,6 +27,7 @@ public class ReaderColumn<T> : ReaderColumn
/// <param name="name">The name of the column.</param>
/// <param name="property">The property being read if any, null otherwise.</param>
/// <param name="getFieldValueExpression">A lambda expression to get field value for the column from the reader.</param>
[Experimental(EFDiagnostics.PrecompiledQueryExperimental)]
public ReaderColumn(
bool nullable,
string? name,
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Query/ReplacingExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static Expression Replace(Expression original, Expression replacement, Ex
/// <param name="replacements">A list of expressions to be used as replacements.</param>
/// <param name="tree">The expression tree in which replacement is going to be performed.</param>
/// <returns>An expression tree with replacements made.</returns>
public static Expression Replace(Expression[] originals, Expression[] replacements, Expression tree)
public static Expression Replace(IReadOnlyList<Expression> originals, IReadOnlyList<Expression> replacements, Expression tree)
=> new ReplacingExpressionVisitor(originals, replacements).Visit(tree);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public class BufferedDataReaderTest
public async Task Metadata_methods_return_expected_results(bool async)
{
var reader = new FakeDbDataReader(["columnName"], new[] { [new object()], new[] { new object() } });
#pragma warning disable EF9100 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var columns = new ReaderColumn[] { new ReaderColumn<object>(true, null, null, (r, _) => r.GetValue(0)) };
#pragma warning restore EF9100 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var bufferedDataReader = new BufferedDataReader(reader, false);
if (async)
{
Expand Down Expand Up @@ -43,8 +45,10 @@ public async Task Manipulation_methods_perform_expected_actions(bool async)
new List<IList<object[]>> { new[] { new object[] { 1, "a" } }, Array.Empty<object[]>() });
var columns = new ReaderColumn[]
{
#pragma warning disable EF9100 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
new ReaderColumn<int>(false, null, null, (r, _) => r.GetInt32(0)),
new ReaderColumn<object>(true, null, null, (r, _) => r.GetValue(1))
#pragma warning restore EF9100 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
};

var bufferedDataReader = new BufferedDataReader(reader, false);
Expand Down Expand Up @@ -108,7 +112,9 @@ public async Task Manipulation_methods_perform_expected_actions(bool async)
public async Task Initialize_is_idempotent(bool async)
{
var reader = new FakeDbDataReader(["name"], new[] { new[] { new object() } });
#pragma warning disable EF9100 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var columns = new ReaderColumn[] { new ReaderColumn<object>(true, null, null, (r, _) => r.GetValue(0)) };
#pragma warning restore EF9100 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var bufferedReader = new BufferedDataReader(reader, false);

Assert.False(reader.IsClosed);
Expand Down Expand Up @@ -186,7 +192,9 @@ private async Task Verify_method_result<T>(

var columns = new[]
{
#pragma warning disable EF9100 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
ReaderColumn.Create(columnType, true, null, null, getFieldValueLambda)
#pragma warning restore EF9100 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
};

var bufferedReader = new BufferedDataReader(reader, false);
Expand Down

0 comments on commit b25cba7

Please sign in to comment.