From eae3873173cead9c14e0e5df686728a67b5af12c Mon Sep 17 00:00:00 2001 From: Christof Senn Date: Sun, 9 Jun 2024 01:49:54 +0200 Subject: [PATCH] use collection expression --- .../RemoteLinqAsyncQueryProvider`1.cs | 4 +-- .../AsyncQueryExpressionTranslatorContext.cs | 4 +-- .../ExpressionExecution/Helper.cs | 6 ++-- .../EntityFrameworkMethodInfos.cs | 4 +-- .../ExpressionExecution/Helper.cs | 6 ++-- .../ExpressionExecution/Helper.cs | 8 ++--- .../SystemExpressionReWriter.cs | 8 ++--- .../AsyncRemoteQueryProvider`1.cs | 2 +- .../DynamicQuery/DynamicResultMapper.cs | 2 +- .../DynamicQuery/RemoteQueryProvider`1.cs | 2 +- .../DefaultExpressionExecutor.cs | 2 +- .../ExpressionTranslatorContext.cs | 16 +++++----- .../SystemExpressionEvaluator.cs | 8 ++--- .../VariableQueryArgumentVisitor.cs | 4 +-- .../Include/IncludeQueryableExtensions.cs | 8 ++--- .../RemoteIncludeExpressionReWriter.cs | 2 +- src/Remote.Linq/MethodInfos.Enumerable.cs | 20 ++++++------ src/Remote.Linq/MethodInfos.Expression.cs | 2 +- src/Remote.Linq/MethodInfos.Queryable.cs | 32 +++++++++---------- .../SimpleQueryQueryableExtensions.cs | 4 +-- .../TestSupport/TaskAsyncQueryProvider.cs | 4 +-- ...hen_using_async_numeric_linq_operations.cs | 8 ++--- .../Include/When_using_include.cs | 14 ++++---- .../RemoteQueryable/When_running_query.cs | 4 +-- ...When_using_remote_linq_as_linq_provider.cs | 2 +- .../Expressions/When_using_BlockExpression.cs | 2 +- ...hen_using_ConstExpression_of_expression.cs | 2 +- .../When_using_GotoAndLabelExpressions.cs | 2 +- ...sing_GotoAndLabelExpressions_with_names.cs | 4 +-- ...Expressions_with_nested_BlockExpression.cs | 4 +-- .../When_using_IfElseExpressions.cs | 4 +-- ...using_LambdaExpression_returnung_a_type.cs | 2 +- .../When_using_TryFinallyExpressions.cs | 4 +-- ...sing_local_variable_query_argument_list.cs | 4 +-- ...cal_variable_query_string_argument_list.cs | 4 +-- test/Remote.Linq.Tests/TestData.cs | 4 +-- test/Remote.Linq.Tests/TestHelper.cs | 2 +- 37 files changed, 107 insertions(+), 107 deletions(-) diff --git a/src/Remote.Linq.Async.Queryable/DynamicQuery/RemoteLinqAsyncQueryProvider`1.cs b/src/Remote.Linq.Async.Queryable/DynamicQuery/RemoteLinqAsyncQueryProvider`1.cs index 09ad3adc..e4666e5d 100644 --- a/src/Remote.Linq.Async.Queryable/DynamicQuery/RemoteLinqAsyncQueryProvider`1.cs +++ b/src/Remote.Linq.Async.Queryable/DynamicQuery/RemoteLinqAsyncQueryProvider`1.cs @@ -106,14 +106,14 @@ public async ValueTask ExecuteAsync(SystemLinq.Expression expr private TResult MapAsyncEnumerable(Type elementType, IAsyncEnumerable source, CancellationToken cancellation) { var method = _mapAsyncEnumerableMethodInfo.MakeGenericMethod(elementType); - var result = method.Invoke(null, new object[] { source, _resultMapper, cancellation }); + var result = method.Invoke(null, [source, _resultMapper, cancellation]); return (TResult)result!; } private ValueTask MapSingleElementStream(IAsyncEnumerable source, CancellationToken cancellation) { var method = _mapSingleElementStreamMethodInfo.MakeGenericMethod(typeof(TResult)); - var result = method.Invoke(null, new object[] { source, _resultMapper, cancellation }); + var result = method.Invoke(null, [source, _resultMapper, cancellation]); return (ValueTask)result!; } diff --git a/src/Remote.Linq.Async.Queryable/ExpressionExecution/AsyncQueryExpressionTranslatorContext.cs b/src/Remote.Linq.Async.Queryable/ExpressionExecution/AsyncQueryExpressionTranslatorContext.cs index 3bd74968..8aab2307 100644 --- a/src/Remote.Linq.Async.Queryable/ExpressionExecution/AsyncQueryExpressionTranslatorContext.cs +++ b/src/Remote.Linq.Async.Queryable/ExpressionExecution/AsyncQueryExpressionTranslatorContext.cs @@ -39,11 +39,11 @@ protected override bool ShouldMapToDynamicObject(IEnumerable collection) var genericTypeArguments = default(Type[]); if (obj?.GetType().Implements(typeof(IAsyncGrouping<,>), out genericTypeArguments) is true) { - obj = MapAsyncGroupToDynamicObjectGraphMethod(genericTypeArguments!).Invoke(null, new[] { obj }); + obj = MapAsyncGroupToDynamicObjectGraphMethod(genericTypeArguments!).Invoke(null, [obj]); } else if (obj?.GetType().Implements(typeof(IAsyncEnumerable<>), out genericTypeArguments) is true) { - obj = MapAsyncEnumerableMethod(genericTypeArguments!).Invoke(null, new[] { obj }); + obj = MapAsyncEnumerableMethod(genericTypeArguments!).Invoke(null, [obj]); } return base.MapToDynamicObjectGraph(obj, setTypeInformation); diff --git a/src/Remote.Linq.Async.Queryable/ExpressionExecution/Helper.cs b/src/Remote.Linq.Async.Queryable/ExpressionExecution/Helper.cs index d683a861..8f4c0e07 100644 --- a/src/Remote.Linq.Async.Queryable/ExpressionExecution/Helper.cs +++ b/src/Remote.Linq.Async.Queryable/ExpressionExecution/Helper.cs @@ -22,7 +22,7 @@ internal static class Helper { task.AssertNotNull(); resultType.AssertNotNull(); - var result = ToSingleElementStreamMethod(resultType).Invoke(null, new[] { task }); + var result = ToSingleElementStreamMethod(resultType).Invoke(null, [task]); return (IAsyncEnumerable)result!; } @@ -36,7 +36,7 @@ internal static class Helper public static IAsyncEnumerable MapAsyncEnumerable(object asyncEnumerable, Type itemType) { itemType.AssertNotNull(); - var result = MapAsyncEnumerableMethod(itemType).Invoke(null, new[] { asyncEnumerable }); + var result = MapAsyncEnumerableMethod(itemType).Invoke(null, [asyncEnumerable]); return (IAsyncEnumerable)result!; } @@ -55,7 +55,7 @@ internal static class Helper { task.AssertNotNull(); resultType.AssertNotNull(); - var result = MapTaskAsyncMethod(resultType).Invoke(null, new[] { task }); + var result = MapTaskAsyncMethod(resultType).Invoke(null, [task]); return (ValueTask)result!; } diff --git a/src/Remote.Linq.EntityFramework/EntityFrameworkMethodInfos.cs b/src/Remote.Linq.EntityFramework/EntityFrameworkMethodInfos.cs index 78f9db89..3053cbaf 100644 --- a/src/Remote.Linq.EntityFramework/EntityFrameworkMethodInfos.cs +++ b/src/Remote.Linq.EntityFramework/EntityFrameworkMethodInfos.cs @@ -35,13 +35,13 @@ private TProperty() internal static readonly MethodInfo StringIncludeMethodInfo = typeof(System.Data.Entity.QueryableExtensions).GetMethodEx( nameof(System.Data.Entity.QueryableExtensions.Include), - new[] { typeof(T) }, + [typeof(T)], typeof(IQueryable), typeof(string)); internal static readonly MethodInfo IncludeMethodInfo = typeof(System.Data.Entity.QueryableExtensions).GetMethodEx( nameof(System.Data.Entity.QueryableExtensions.Include), - new[] { typeof(T), typeof(TProperty) }, + [typeof(T), typeof(TProperty)], typeof(IQueryable), typeof(Expression>)); } \ No newline at end of file diff --git a/src/Remote.Linq.EntityFramework/ExpressionExecution/Helper.cs b/src/Remote.Linq.EntityFramework/ExpressionExecution/Helper.cs index 3e4ae8a9..ac8c51bd 100644 --- a/src/Remote.Linq.EntityFramework/ExpressionExecution/Helper.cs +++ b/src/Remote.Linq.EntityFramework/ExpressionExecution/Helper.cs @@ -38,19 +38,19 @@ private TEntity() private static readonly MethodInfo QueryableToListAsyncMethod = typeof(QueryableExtensions).GetMethodEx( nameof(QueryableExtensions.ToListAsync), - new[] { typeof(TSource) }, + [typeof(TSource)], typeof(IQueryable), typeof(CancellationToken)); private static readonly MethodInfo DbContextSetMethod = typeof(DbContext).GetMethodEx( nameof(DbContext.Set), - genericArguments: new[] { typeof(TEntity) }); + genericArguments: [typeof(TEntity)]); internal static Task ToListAsync(IQueryable source, CancellationToken cancellation) { source.AssertNotNull(); var method = QueryableToListAsyncMethod.MakeGenericMethod(source.ElementType); - var task = method.Invoke(null, new object[] { source, cancellation }); + var task = method.Invoke(null, [source, cancellation]); return (Task)task!; } diff --git a/src/Remote.Linq.EntityFrameworkCore/ExpressionExecution/Helper.cs b/src/Remote.Linq.EntityFrameworkCore/ExpressionExecution/Helper.cs index 345f97fa..c189f7fe 100644 --- a/src/Remote.Linq.EntityFrameworkCore/ExpressionExecution/Helper.cs +++ b/src/Remote.Linq.EntityFrameworkCore/ExpressionExecution/Helper.cs @@ -40,13 +40,13 @@ private TEntity() private static readonly MethodInfo _entityFrameworkQueryableToListAsyncMethod = typeof(EntityFrameworkQueryableExtensions).GetMethodEx( nameof(EntityFrameworkQueryableExtensions.ToListAsync), - new[] { typeof(TSource) }, + [typeof(TSource)], typeof(IQueryable), typeof(CancellationToken)); private static readonly MethodInfo _dbContextSetMethod = typeof(DbContext).GetMethodEx( nameof(DbContext.Set), - genericArguments: new[] { typeof(TEntity) }); + genericArguments: [typeof(TEntity)]); private static readonly MethodInfo _executeAsAsyncStreamMethod = typeof(Helper).GetMethodEx(nameof(ExecuteAsAsyncStream)); @@ -54,7 +54,7 @@ internal static Task ToListAsync(IQueryable source, CancellationToken cancellati { source.AssertNotNull(); var method = _entityFrameworkQueryableToListAsyncMethod.MakeGenericMethod(source.ElementType); - var task = method.Invoke(null, new object[] { source, cancellation }); + var task = method.Invoke(null, [source, cancellation]); return (Task)task!; } @@ -88,7 +88,7 @@ public IQueryable GetQueryableSet(Type type) { queryable.AssertNotNull(); var method = _executeAsAsyncStreamMethod.MakeGenericMethod(queryable.ElementType); - var asyncStream = method.Invoke(null, new object[] { queryable, cancellation }); + var asyncStream = method.Invoke(null, [queryable, cancellation]); return (IAsyncEnumerable)asyncStream!; } diff --git a/src/Remote.Linq.EntityFrameworkCore/ExpressionVisitors/SystemExpressionReWriter.cs b/src/Remote.Linq.EntityFrameworkCore/ExpressionVisitors/SystemExpressionReWriter.cs index b4d8403a..8a6bbc36 100644 --- a/src/Remote.Linq.EntityFrameworkCore/ExpressionVisitors/SystemExpressionReWriter.cs +++ b/src/Remote.Linq.EntityFrameworkCore/ExpressionVisitors/SystemExpressionReWriter.cs @@ -74,25 +74,25 @@ private TPreviousProperty() internal static readonly MethodInfo StringIncludeMethodInfo = typeof(EntityFrameworkQueryableExtensions).GetMethodEx( nameof(EntityFrameworkQueryableExtensions.Include), - new[] { typeof(TEntity) }, + [typeof(TEntity)], typeof(IQueryable), typeof(string)); internal static readonly MethodInfo IncludeMethodInfo = typeof(EntityFrameworkQueryableExtensions).GetMethodEx( nameof(EntityFrameworkQueryableExtensions.Include), - new[] { typeof(TEntity), typeof(TProperty) }, + [typeof(TEntity), typeof(TProperty)], typeof(IQueryable), typeof(Expression>)); internal static readonly MethodInfo ThenIncludeAfterEnumerableMethodInfo = typeof(EntityFrameworkQueryableExtensions).GetMethodEx( nameof(EntityFrameworkQueryableExtensions.ThenInclude), - new[] { typeof(TEntity), typeof(TPreviousProperty), typeof(TProperty) }, + [typeof(TEntity), typeof(TPreviousProperty), typeof(TProperty)], typeof(Microsoft.EntityFrameworkCore.Query.IIncludableQueryable>), typeof(Expression>)); internal static readonly MethodInfo ThenIncludeAfterReferenceMethodInfo = typeof(EntityFrameworkQueryableExtensions).GetMethodEx( nameof(EntityFrameworkQueryableExtensions.ThenInclude), - new[] { typeof(TEntity), typeof(TPreviousProperty), typeof(TProperty) }, + [typeof(TEntity), typeof(TPreviousProperty), typeof(TProperty)], typeof(Microsoft.EntityFrameworkCore.Query.IIncludableQueryable), typeof(Expression>)); } diff --git a/src/Remote.Linq/DynamicQuery/AsyncRemoteQueryProvider`1.cs b/src/Remote.Linq/DynamicQuery/AsyncRemoteQueryProvider`1.cs index d7f70c2a..6914d487 100644 --- a/src/Remote.Linq/DynamicQuery/AsyncRemoteQueryProvider`1.cs +++ b/src/Remote.Linq/DynamicQuery/AsyncRemoteQueryProvider`1.cs @@ -18,7 +18,7 @@ namespace Remote.Linq.DynamicQuery; public sealed class AsyncRemoteQueryProvider : IAsyncRemoteQueryProvider { private static readonly MethodInfo _executeMethod = typeof(AsyncRemoteQueryProvider) - .GetMethodEx(nameof(Execute), new[] { typeof(MethodInfos.TResult) }, typeof(SystemLinq.Expression)); + .GetMethodEx(nameof(Execute), [typeof(MethodInfos.TResult)], typeof(SystemLinq.Expression)); private readonly Func> _asyncDataProvider; private readonly IAsyncQueryResultMapper _resultMapper; diff --git a/src/Remote.Linq/DynamicQuery/DynamicResultMapper.cs b/src/Remote.Linq/DynamicQuery/DynamicResultMapper.cs index 1645eab8..ee1956dd 100644 --- a/src/Remote.Linq/DynamicQuery/DynamicResultMapper.cs +++ b/src/Remote.Linq/DynamicQuery/DynamicResultMapper.cs @@ -94,7 +94,7 @@ internal static TResult MapToSingleResult(Type elementType, System.Coll var hasPredicate = methodCallExpression.Arguments.Count is 2; var arguments = hasPredicate ? new object[] { result, GetTruePredicate(elementType) } - : new object[] { result }; + : [result]; var method = methodCallExpression.Method.Name.EndsWith("OrDefault", StringComparison.Ordinal) ? (hasPredicate ? MethodInfos.Enumerable.SingleOrDefaultWithPredicate : MethodInfos.Enumerable.SingleOrDefault) : (hasPredicate ? MethodInfos.Enumerable.SingleWithPredicate : MethodInfos.Enumerable.Single); diff --git a/src/Remote.Linq/DynamicQuery/RemoteQueryProvider`1.cs b/src/Remote.Linq/DynamicQuery/RemoteQueryProvider`1.cs index a6b9b906..9774e6e7 100644 --- a/src/Remote.Linq/DynamicQuery/RemoteQueryProvider`1.cs +++ b/src/Remote.Linq/DynamicQuery/RemoteQueryProvider`1.cs @@ -12,7 +12,7 @@ namespace Remote.Linq.DynamicQuery; public sealed class RemoteQueryProvider : IRemoteQueryProvider { private static readonly MethodInfo _executeMethod = typeof(RemoteQueryProvider) - .GetMethodEx(nameof(Execute), new[] { typeof(MethodInfos.TResult) }, typeof(Expression)); + .GetMethodEx(nameof(Execute), [typeof(MethodInfos.TResult)], typeof(Expression)); private readonly Func _dataProvider; private readonly IQueryResultMapper _resultMapper; diff --git a/src/Remote.Linq/ExpressionExecution/DefaultExpressionExecutor.cs b/src/Remote.Linq/ExpressionExecution/DefaultExpressionExecutor.cs index f561421a..cf172734 100644 --- a/src/Remote.Linq/ExpressionExecution/DefaultExpressionExecutor.cs +++ b/src/Remote.Linq/ExpressionExecution/DefaultExpressionExecutor.cs @@ -62,7 +62,7 @@ private DynamicObject Map(object? value, Type? type) : _mapper.MapObject(value, _setTypeInformation); private object[] MapArray(object array, Type elementType) - => (object[])_mapArrayMethodInfo.MakeGenericMethod(elementType).Invoke(this, new[] { array })!; + => (object[])_mapArrayMethodInfo.MakeGenericMethod(elementType).Invoke(this, [array])!; private object[] MapArray(T[] array) => array diff --git a/src/Remote.Linq/ExpressionTranslatorContext.cs b/src/Remote.Linq/ExpressionTranslatorContext.cs index 8036580a..37b61bdf 100644 --- a/src/Remote.Linq/ExpressionTranslatorContext.cs +++ b/src/Remote.Linq/ExpressionTranslatorContext.cs @@ -134,12 +134,12 @@ protected override bool ShouldMapToDynamicObject(IEnumerable collection) typeof(System.Numerics.Complex), typeof(byte[]), } - .SelectMany(x => x.IsValueType ? new[] { x, typeof(Nullable<>).MakeGenericType(x) } : new[] { x }) + .SelectMany(x => x.IsValueType ? new[] { x, typeof(Nullable<>).MakeGenericType(x) } : [x]) .ToHashSet() .Contains; - private static readonly Type[] _unmappedTypes = new[] - { + private static readonly Type[] _unmappedTypes = + [ typeof(CancellationToken), typeof(ConstantQueryArgument), typeof(VariableQueryArgument), @@ -149,12 +149,12 @@ protected override bool ShouldMapToDynamicObject(IEnumerable collection) typeof(SystemLinq.Expression), typeof(IQueryable), typeof(IRemoteLinqQueryable), - }; + ]; - private static readonly Type[] _excludeFromUnmappedTypes = new[] - { + private static readonly Type[] _excludeFromUnmappedTypes = + [ typeof(EnumerableQuery), - }; + ]; /// /// Initializes a new instance of the class. @@ -238,7 +238,7 @@ public ExpressionTranslatorContext( private static object? MapGroupToDynamicObjectGraphMethod(Type[] genericTypeArguments, object group) => _mapGroupToDynamicObjectGraphMethodDefinition .MakeGenericMethod(genericTypeArguments) - .Invoke(null, new[] { group }); + .Invoke(null, [group]); private static Grouping MapGroupToDynamicObjectGraph(IGrouping group) => group is Grouping grouping diff --git a/src/Remote.Linq/ExpressionVisitors/SystemExpressionEvaluator.cs b/src/Remote.Linq/ExpressionVisitors/SystemExpressionEvaluator.cs index c3c407b7..b855c37d 100644 --- a/src/Remote.Linq/ExpressionVisitors/SystemExpressionEvaluator.cs +++ b/src/Remote.Linq/ExpressionVisitors/SystemExpressionEvaluator.cs @@ -166,20 +166,20 @@ private static Expression Evaluate(Expression expression) var elementType = TypeHelper.GetElementType(collectionType); if (expression.Type.IsAssignableFrom(elementType.MakeArrayType())) { - var enumerated = MethodInfos.Enumerable.ToArray.MakeGenericMethod(elementType).Invoke(null, new[] { value }); + var enumerated = MethodInfos.Enumerable.ToArray.MakeGenericMethod(elementType).Invoke(null, [value]); value = enumerated; } else if (value is EnumerableQuery && expression.Type.IsAssignableFrom(typeof(IQueryable<>).MakeGenericType(elementType))) { - var enumerated = MethodInfos.Enumerable.ToArray.MakeGenericMethod(elementType).Invoke(null, new[] { value }); - var queryable = MethodInfos.Queryable.AsQueryable.MakeGenericMethod(elementType).Invoke(null, new[] { enumerated }); + var enumerated = MethodInfos.Enumerable.ToArray.MakeGenericMethod(elementType).Invoke(null, [value]); + var queryable = MethodInfos.Queryable.AsQueryable.MakeGenericMethod(elementType).Invoke(null, [enumerated]); value = queryable; } } return Expression.Property( Expression.New( - typeof(VariableQueryArgument<>).MakeGenericType(expression.Type).GetConstructor(new[] { expression.Type })!, + typeof(VariableQueryArgument<>).MakeGenericType(expression.Type).GetConstructor([expression.Type])!, Expression.Constant(value, expression.Type)), nameof(VariableQueryArgument.Value)); } diff --git a/src/Remote.Linq/ExpressionVisitors/VariableQueryArgumentVisitor.cs b/src/Remote.Linq/ExpressionVisitors/VariableQueryArgumentVisitor.cs index 965c41eb..3290d96d 100644 --- a/src/Remote.Linq/ExpressionVisitors/VariableQueryArgumentVisitor.cs +++ b/src/Remote.Linq/ExpressionVisitors/VariableQueryArgumentVisitor.cs @@ -127,7 +127,7 @@ protected override Expression VisitConstant(ConstantExpression node) { var type = nonGenericQueryArgument.Type.ResolveType(TypeResolver); var value = nonGenericQueryArgument.Value; - var queryArgument = Activator.CreateInstance(typeof(VariableQueryArgument<>).MakeGenericType(type), new[] { value }); + var queryArgument = Activator.CreateInstance(typeof(VariableQueryArgument<>).MakeGenericType(type), [value]); return new ConstantExpression(queryArgument); } @@ -136,7 +136,7 @@ protected override Expression VisitConstant(ConstantExpression node) var elementType = nonGenericQueryArgumentList.ElementType.ResolveType(TypeResolver); var values = nonGenericQueryArgumentList.Values; var methodInfo = CreateVariableQueryArgumentListMethodInfo.MakeGenericMethod(elementType); - var queryArgument = methodInfo.Invoke(null, new object[] { values }); + var queryArgument = methodInfo.Invoke(null, [values]); return new ConstantExpression(queryArgument); } diff --git a/src/Remote.Linq/Include/IncludeQueryableExtensions.cs b/src/Remote.Linq/Include/IncludeQueryableExtensions.cs index 44d15d76..8af51c79 100644 --- a/src/Remote.Linq/Include/IncludeQueryableExtensions.cs +++ b/src/Remote.Linq/Include/IncludeQueryableExtensions.cs @@ -43,7 +43,7 @@ private sealed class TPreviousProperty /// public static readonly MethodInfo StringIncludeMethodInfo = typeof(IncludeQueryableExtensions).GetMethodEx( nameof(IncludeQueryableExtensions.Include), - new[] { typeof(T) }, + [typeof(T)], typeof(IQueryable), typeof(string)); @@ -52,7 +52,7 @@ private sealed class TPreviousProperty /// public static readonly MethodInfo IncludeMethodInfo = typeof(IncludeQueryableExtensions).GetMethodEx( nameof(IncludeQueryableExtensions.Include), - new[] { typeof(T), typeof(TProperty) }, + [typeof(T), typeof(TProperty)], typeof(IQueryable), typeof(Expression>)); @@ -63,7 +63,7 @@ private sealed class TPreviousProperty /// public static readonly MethodInfo ThenIncludeAfterEnumerableMethodInfo = typeof(IncludeQueryableExtensions).GetMethodEx( nameof(IncludeQueryableExtensions.ThenInclude), - new[] { typeof(T), typeof(TPreviousProperty), typeof(TProperty) }, + [typeof(T), typeof(TPreviousProperty), typeof(TProperty)], typeof(IIncludableQueryable>), typeof(Expression>)); @@ -74,7 +74,7 @@ private sealed class TPreviousProperty /// public static readonly MethodInfo ThenIncludeAfterReferenceMethodInfo = typeof(IncludeQueryableExtensions).GetMethodEx( nameof(IncludeQueryableExtensions.ThenInclude), - new[] { typeof(T), typeof(TPreviousProperty), typeof(TProperty) }, + [typeof(T), typeof(TPreviousProperty), typeof(TProperty)], typeof(IIncludableQueryable), typeof(Expression>)); diff --git a/src/Remote.Linq/Include/RemoteIncludeExpressionReWriter.cs b/src/Remote.Linq/Include/RemoteIncludeExpressionReWriter.cs index 5aab635a..1a9bfb15 100644 --- a/src/Remote.Linq/Include/RemoteIncludeExpressionReWriter.cs +++ b/src/Remote.Linq/Include/RemoteIncludeExpressionReWriter.cs @@ -83,7 +83,7 @@ protected override Expression VisitConstant(ConstantExpression node) }; var m = method.MakeGenericMethod(args); - var expression = (Expression)m.Invoke(null, new[] { node.Value })!; + var expression = (Expression)m.Invoke(null, [node.Value])!; return Visit(expression); } diff --git a/src/Remote.Linq/MethodInfos.Enumerable.cs b/src/Remote.Linq/MethodInfos.Enumerable.cs index 36fa5f4c..1714439f 100644 --- a/src/Remote.Linq/MethodInfos.Enumerable.cs +++ b/src/Remote.Linq/MethodInfos.Enumerable.cs @@ -14,55 +14,55 @@ internal static class Enumerable { internal static readonly MethodInfo Cast = typeof(System.Linq.Enumerable).GetMethodEx( nameof(System.Linq.Enumerable.Cast), - new[] { typeof(TResult) }, + [typeof(TResult)], typeof(IEnumerable)); internal static readonly MethodInfo OfType = typeof(System.Linq.Enumerable).GetMethodEx( nameof(System.Linq.Enumerable.OfType), - new[] { typeof(TResult) }, + [typeof(TResult)], typeof(IEnumerable)); internal static readonly MethodInfo ToArray = typeof(System.Linq.Enumerable).GetMethodEx( nameof(System.Linq.Enumerable.ToArray), - new[] { typeof(TSource) }, + [typeof(TSource)], typeof(IEnumerable)); internal static readonly MethodInfo ToList = typeof(System.Linq.Enumerable).GetMethodEx( nameof(System.Linq.Enumerable.ToList), - new[] { typeof(TSource) }, + [typeof(TSource)], typeof(IEnumerable)); internal static readonly MethodInfo Contains = typeof(System.Linq.Enumerable).GetMethodEx( nameof(System.Linq.Enumerable.Contains), - new[] { typeof(TSource) }, + [typeof(TSource)], typeof(IEnumerable), typeof(TSource)); internal static readonly MethodInfo Select = typeof(System.Linq.Enumerable).GetMethodEx( nameof(System.Linq.Enumerable.Select), - new[] { typeof(TSource), typeof(TResult) }, + [typeof(TSource), typeof(TResult)], typeof(IEnumerable), typeof(Func)); internal static readonly MethodInfo Single = typeof(System.Linq.Enumerable).GetMethodEx( nameof(System.Linq.Enumerable.Single), - new[] { typeof(TSource) }, + [typeof(TSource)], typeof(IEnumerable)); internal static readonly MethodInfo SingleWithPredicate = typeof(System.Linq.Enumerable).GetMethodEx( nameof(System.Linq.Enumerable.Single), - new[] { typeof(TSource) }, + [typeof(TSource)], typeof(IEnumerable), typeof(Func)); internal static readonly MethodInfo SingleOrDefault = typeof(System.Linq.Enumerable).GetMethodEx( nameof(System.Linq.Enumerable.SingleOrDefault), - new[] { typeof(TSource) }, + [typeof(TSource)], typeof(IEnumerable)); internal static readonly MethodInfo SingleOrDefaultWithPredicate = typeof(System.Linq.Enumerable).GetMethodEx( nameof(System.Linq.Enumerable.SingleOrDefault), - new[] { typeof(TSource) }, + [typeof(TSource)], typeof(IEnumerable), typeof(Func)); } diff --git a/src/Remote.Linq/MethodInfos.Expression.cs b/src/Remote.Linq/MethodInfos.Expression.cs index 65766bc8..aba484ac 100644 --- a/src/Remote.Linq/MethodInfos.Expression.cs +++ b/src/Remote.Linq/MethodInfos.Expression.cs @@ -12,7 +12,7 @@ internal static class Expression { internal static readonly MethodInfo Lambda = typeof(System.Linq.Expressions.Expression).GetMethodEx( nameof(System.Linq.Expressions.Expression.Lambda), - new[] { typeof(TDelegate) }, + [typeof(TDelegate)], typeof(System.Linq.Expressions.Expression), typeof(ParameterExpression[])); } diff --git a/src/Remote.Linq/MethodInfos.Queryable.cs b/src/Remote.Linq/MethodInfos.Queryable.cs index 2ea9819e..932d2447 100644 --- a/src/Remote.Linq/MethodInfos.Queryable.cs +++ b/src/Remote.Linq/MethodInfos.Queryable.cs @@ -19,25 +19,25 @@ internal static class Queryable internal static readonly MethodInfo OrderBy = GetQueryableMethod( nameof(System.Linq.Queryable.OrderBy), - new[] { typeof(TSource), typeof(TKey) }, + [typeof(TSource), typeof(TKey)], typeof(IQueryable), typeof(Expression>)); internal static readonly MethodInfo OrderByDescending = GetQueryableMethod( nameof(System.Linq.Queryable.OrderByDescending), - new[] { typeof(TSource), typeof(TKey) }, + [typeof(TSource), typeof(TKey)], typeof(IQueryable), typeof(Expression>)); internal static readonly MethodInfo ThenBy = GetQueryableMethod( nameof(System.Linq.Queryable.ThenBy), - new[] { typeof(TSource), typeof(TKey) }, + [typeof(TSource), typeof(TKey)], typeof(IOrderedQueryable), typeof(Expression>)); internal static readonly MethodInfo ThenByDescending = GetQueryableMethod( nameof(System.Linq.Queryable.ThenByDescending), - new[] { typeof(TSource), typeof(TKey) }, + [typeof(TSource), typeof(TKey)], typeof(IOrderedQueryable), typeof(Expression>)); @@ -48,14 +48,14 @@ internal static class Queryable internal static readonly MethodInfo AggregateWithSeed = GetQueryableMethod( nameof(System.Linq.Queryable.Aggregate), - new[] { typeof(TSource), typeof(TAccumulate) }, + [typeof(TSource), typeof(TAccumulate)], typeof(IQueryable), typeof(TAccumulate), typeof(Expression>)); internal static readonly MethodInfo AggregateWithSeedAndSelector = GetQueryableMethod( nameof(System.Linq.Queryable.Aggregate), - new[] { typeof(TSource), typeof(TAccumulate), typeof(TResult) }, + [typeof(TSource), typeof(TAccumulate), typeof(TResult)], typeof(IQueryable), typeof(TAccumulate), typeof(Expression>), @@ -190,26 +190,26 @@ internal static class Queryable internal static readonly MethodInfo MaxWithSelector = GetQueryableMethod( nameof(System.Linq.Queryable.Max), - new[] { typeof(TSource), typeof(TResult) }, + [typeof(TSource), typeof(TResult)], typeof(IQueryable), typeof(Expression>)); #if NET6_0_OR_GREATER internal static readonly MethodInfo MaxWithComparer = GetQueryableMethod( nameof(System.Linq.Queryable.Max), - new[] { typeof(TSource) }, + [typeof(TSource)], typeof(IQueryable), typeof(IComparer)); internal static readonly MethodInfo MaxBy = GetQueryableMethod( nameof(System.Linq.Queryable.MaxBy), - new[] { typeof(TSource), typeof(TKey) }, + [typeof(TSource), typeof(TKey)], typeof(IQueryable), typeof(Expression>)); internal static readonly MethodInfo MaxByWithComparer = GetQueryableMethod( nameof(System.Linq.Queryable.MaxBy), - new[] { typeof(TSource), typeof(TKey) }, + [typeof(TSource), typeof(TKey)], typeof(IQueryable), typeof(Expression>), typeof(IComparer)); @@ -221,26 +221,26 @@ internal static class Queryable internal static readonly MethodInfo MinWithSelector = GetQueryableMethod( nameof(System.Linq.Queryable.Min), - new[] { typeof(TSource), typeof(TResult) }, + [typeof(TSource), typeof(TResult)], typeof(IQueryable), typeof(Expression>)); #if NET6_0_OR_GREATER internal static readonly MethodInfo MinWithComparer = GetQueryableMethod( nameof(System.Linq.Queryable.Min), - new[] { typeof(TSource) }, + [typeof(TSource)], typeof(IQueryable), typeof(IComparer)); internal static readonly MethodInfo MinBy = GetQueryableMethod( nameof(System.Linq.Queryable.MinBy), - new[] { typeof(TSource), typeof(TKey) }, + [typeof(TSource), typeof(TKey)], typeof(IQueryable), typeof(Expression>)); internal static readonly MethodInfo MinByWithComparer = GetQueryableMethod( nameof(System.Linq.Queryable.MinBy), - new[] { typeof(TSource), typeof(TKey) }, + [typeof(TSource), typeof(TKey)], typeof(IQueryable), typeof(Expression>), typeof(IComparer)); @@ -299,7 +299,7 @@ internal static class Queryable internal static readonly MethodInfo Select = GetQueryableMethod( nameof(System.Linq.Queryable.Select), - new[] { typeof(TSource), typeof(TResult) }, + [typeof(TSource), typeof(TResult)], typeof(IQueryable), typeof(Expression>)); @@ -324,7 +324,7 @@ private static MethodInfo GetSumWithSelector() => GetQueryableMethod( typeof(Expression>)); private static MethodInfo GetQueryableMethod(string name, params Type[] parameterTypes) - => GetQueryableMethod(name, new[] { typeof(TSource) }, parameterTypes); + => GetQueryableMethod(name, [typeof(TSource)], parameterTypes); private static MethodInfo GetQueryableMethod(string name, Type[] genericArgumentTypes, params Type[] parameterTypes) => typeof(System.Linq.Queryable).GetMethodEx(name, genericArgumentTypes, parameterTypes); diff --git a/src/Remote.Linq/SimpleQuery/SimpleQueryQueryableExtensions.cs b/src/Remote.Linq/SimpleQuery/SimpleQueryQueryableExtensions.cs index 5b305f48..4f0ef4ec 100644 --- a/src/Remote.Linq/SimpleQuery/SimpleQueryQueryableExtensions.cs +++ b/src/Remote.Linq/SimpleQuery/SimpleQueryQueryableExtensions.cs @@ -32,10 +32,10 @@ private static IOrderedQueryable Sort(this IQueryable queryable, System var funcType = typeof(Func<,>).MakeGenericType(typeof(T), resultType); var lambdaExpressionMethodInfo = MethodInfos.Expression.Lambda.MakeGenericMethod(funcType); - var funcExpression = lambdaExpressionMethodInfo.Invoke(null, new object[] { exp, lambdaExpression.Parameters.ToArray() }); + var funcExpression = lambdaExpressionMethodInfo.Invoke(null, [exp, lambdaExpression.Parameters.ToArray()]); var method = methodInfo.MakeGenericMethod(typeof(T), resultType); - var result = method.Invoke(null, new object[] { queryable, funcExpression! }); + var result = method.Invoke(null, [queryable, funcExpression!]); return (IOrderedQueryable)result!; } diff --git a/src/Remote.Linq/TestSupport/TaskAsyncQueryProvider.cs b/src/Remote.Linq/TestSupport/TaskAsyncQueryProvider.cs index 62831b06..f97eb4d4 100644 --- a/src/Remote.Linq/TestSupport/TaskAsyncQueryProvider.cs +++ b/src/Remote.Linq/TestSupport/TaskAsyncQueryProvider.cs @@ -18,10 +18,10 @@ namespace Remote.Linq.TestSupport; internal sealed class TaskAsyncQueryProvider : IAsyncRemoteQueryProvider { private static readonly MethodInfo _executeMethod = typeof(TaskAsyncQueryProvider) - .GetMethodEx(nameof(Execute), new[] { typeof(MethodInfos.TResult) }, typeof(Expression)); + .GetMethodEx(nameof(Execute), [typeof(MethodInfos.TResult)], typeof(Expression)); private static readonly MethodInfo _createQueryMethod = typeof(TaskAsyncQueryProvider) - .GetMethodEx(nameof(CreateQuery), new[] { typeof(MethodInfos.TElement) }, typeof(Expression)); + .GetMethodEx(nameof(CreateQuery), [typeof(MethodInfos.TElement)], typeof(Expression)); private readonly IExpressionTranslatorContext _context; diff --git a/test/Remote.Linq.Tests/AsyncQueryableExtensions/When_using_async_numeric_linq_operations.cs b/test/Remote.Linq.Tests/AsyncQueryableExtensions/When_using_async_numeric_linq_operations.cs index 46b62e54..d5e0987f 100644 --- a/test/Remote.Linq.Tests/AsyncQueryableExtensions/When_using_async_numeric_linq_operations.cs +++ b/test/Remote.Linq.Tests/AsyncQueryableExtensions/When_using_async_numeric_linq_operations.cs @@ -31,7 +31,7 @@ public static IEnumerable TestSetup get { IScenario[] scenarios = - { + [ new ScenarioFor(x => 2 * x, 0, 102, -5), new ScenarioFor(x => 2 * x, null, 102, -5), @@ -46,9 +46,9 @@ public static IEnumerable TestSetup new ScenarioFor(x => 2 * x, 0, 1.02d, -5), new ScenarioFor(x => 2 * x, null, 1.02d, -5), - }; - string[] methods = { "Sum", "Average" }; - bool[] withSelectorFlags = { false, true }; + ]; + string[] methods = ["Sum", "Average"]; + bool[] withSelectorFlags = [false, true]; return from scenario in scenarios diff --git a/test/Remote.Linq.Tests/Include/When_using_include.cs b/test/Remote.Linq.Tests/Include/When_using_include.cs index 53c0f205..60ba2395 100644 --- a/test/Remote.Linq.Tests/Include/When_using_include.cs +++ b/test/Remote.Linq.Tests/Include/When_using_include.cs @@ -26,7 +26,7 @@ public With_include_path_string() .ToList(); } - protected override string[] ExpectedIncludePaths => new[] { "Children.Parent.Children.Parent" }; + protected override string[] ExpectedIncludePaths => ["Children.Parent.Children.Parent"]; } public class With_include_path : When_using_include @@ -40,7 +40,7 @@ public With_include_path() .ToList(); } - protected override string[] ExpectedIncludePaths => new[] { "Children.Parent.Children.Parent" }; + protected override string[] ExpectedIncludePaths => ["Children.Parent.Children.Parent"]; } public class With_include_reference_collection : When_using_include @@ -54,7 +54,7 @@ public With_include_reference_collection() .ToList(); } - protected override string[] ExpectedIncludePaths => new[] { "Children" }; + protected override string[] ExpectedIncludePaths => ["Children"]; } public class With_include_on_subtype : When_using_include @@ -69,7 +69,7 @@ public With_include_on_subtype() .ToList(); } - protected override string[] ExpectedIncludePaths => new[] { "Parent" }; + protected override string[] ExpectedIncludePaths => ["Parent"]; } public class With_include_reference : When_using_include @@ -83,7 +83,7 @@ public With_include_reference() .ToList(); } - protected override string[] ExpectedIncludePaths => new[] { "Parent" }; + protected override string[] ExpectedIncludePaths => ["Parent"]; protected override Type QueryResourceType => typeof(Child); } @@ -101,7 +101,7 @@ public With_multiple_include() .ToList(); } - protected override string[] ExpectedIncludePaths => new[] { "Parent.Children", "Siblings.Siblings", "Siblings.Parent" }; + protected override string[] ExpectedIncludePaths => ["Parent.Children", "Siblings.Siblings", "Siblings.Parent"]; protected override Type QueryResourceType => typeof(Child); } @@ -117,7 +117,7 @@ public With_then_include() .ToList(); } - protected override string[] ExpectedIncludePaths => new[] { "Children.Parent.Children.Parent" }; + protected override string[] ExpectedIncludePaths => ["Children.Parent.Children.Parent"]; } private class Child diff --git a/test/Remote.Linq.Tests/RemoteQueryable/When_running_query.cs b/test/Remote.Linq.Tests/RemoteQueryable/When_running_query.cs index 95afc9c6..ab9733a8 100644 --- a/test/Remote.Linq.Tests/RemoteQueryable/When_running_query.cs +++ b/test/Remote.Linq.Tests/RemoteQueryable/When_running_query.cs @@ -337,7 +337,7 @@ where g.Select(_ => _.p.CategoryId).Distinct().Count() > 1 [Fact] public void Should_return_orders_joined_with_chars_array_closure() { - char[] array = { 'h', 'e', 'l', 'l', 'o' }; + char[] array = ['h', 'e', 'l', 'l', 'o']; var joinLocalVariable = ( from i in _orderItemQueryable from s in array @@ -1062,7 +1062,7 @@ private void RunTestMethod(string methodName, Type genericType, object argument) => GetType() .GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .MakeGenericMethod(genericType) - .Invoke(this, new[] { argument }); + .Invoke(this, [argument]); [Fact] public void Should_query_value_created_using_default_operator() diff --git a/test/Remote.Linq.Tests/RemoteQueryableFactory/When_using_remote_linq_as_linq_provider.cs b/test/Remote.Linq.Tests/RemoteQueryableFactory/When_using_remote_linq_as_linq_provider.cs index 55b7e751..e53c509a 100644 --- a/test/Remote.Linq.Tests/RemoteQueryableFactory/When_using_remote_linq_as_linq_provider.cs +++ b/test/Remote.Linq.Tests/RemoteQueryableFactory/When_using_remote_linq_as_linq_provider.cs @@ -43,7 +43,7 @@ public void Should_execute_as_untyped_queryable() public void Should_support_method_call_expression() { var src = RemoteItems; - var result = (int)src.Provider.Execute(Expression.Call(typeof(Queryable), nameof(Queryable.Count), new[] { src.ElementType }, new[] { src.Expression })); + var result = (int)src.Provider.Execute(Expression.Call(typeof(Queryable), nameof(Queryable.Count), [src.ElementType], [src.Expression])); result.ShouldBe(1); } } \ No newline at end of file diff --git a/test/Remote.Linq.Tests/Serialization/Expressions/When_using_BlockExpression.cs b/test/Remote.Linq.Tests/Serialization/Expressions/When_using_BlockExpression.cs index 7df3f787..e530feec 100644 --- a/test/Remote.Linq.Tests/Serialization/Expressions/When_using_BlockExpression.cs +++ b/test/Remote.Linq.Tests/Serialization/Expressions/When_using_BlockExpression.cs @@ -96,7 +96,7 @@ protected When_using_BlockExpression(Func { var expression = Expression.IfThenElse( Expression.MakeBinary(ExpressionType.LessThan, Expression.Constant(5), Expression.Constant(2)), - Expression.Throw(Expression.New(typeof(Exception).GetConstructor(new[] { typeof(string) }), Expression.Constant("The condition is true."))), - Expression.Throw(Expression.New(typeof(Exception).GetConstructor(new[] { typeof(string) }), Expression.Constant("The condition is false.")))); + Expression.Throw(Expression.New(typeof(Exception).GetConstructor([typeof(string)]), Expression.Constant("The condition is true."))), + Expression.Throw(Expression.New(typeof(Exception).GetConstructor([typeof(string)]), Expression.Constant("The condition is false.")))); _originalExpression = expression; diff --git a/test/Remote.Linq.Tests/Serialization/Expressions/When_using_LambdaExpression_returnung_a_type.cs b/test/Remote.Linq.Tests/Serialization/Expressions/When_using_LambdaExpression_returnung_a_type.cs index a04f5a02..a5ab4cc5 100644 --- a/test/Remote.Linq.Tests/Serialization/Expressions/When_using_LambdaExpression_returnung_a_type.cs +++ b/test/Remote.Linq.Tests/Serialization/Expressions/When_using_LambdaExpression_returnung_a_type.cs @@ -67,7 +67,7 @@ public With_protobuf_net_serializer() public class With_xml_serializer : When_using_LambdaExpression_returnung_a_type { public With_xml_serializer() - : base(x => XmlSerializationHelper.CloneExpression(x, new[] { typeof(List), typeof(Aqua.TypeSystem.TypeInfo[]) })) + : base(x => XmlSerializationHelper.CloneExpression(x, [typeof(List), typeof(Aqua.TypeSystem.TypeInfo[])])) { } } diff --git a/test/Remote.Linq.Tests/Serialization/Expressions/When_using_TryFinallyExpressions.cs b/test/Remote.Linq.Tests/Serialization/Expressions/When_using_TryFinallyExpressions.cs index b10bf465..1c686b73 100644 --- a/test/Remote.Linq.Tests/Serialization/Expressions/When_using_TryFinallyExpressions.cs +++ b/test/Remote.Linq.Tests/Serialization/Expressions/When_using_TryFinallyExpressions.cs @@ -90,8 +90,8 @@ protected When_using_TryFinallyExpressions(Func DataContractSerializationHelper.CloneExpression(x, new[] { typeof(List) })) + : base(x => DataContractSerializationHelper.CloneExpression(x, [typeof(List)])) { } } @@ -64,7 +64,7 @@ public With_protobuf_net_serializer() public class With_xml_serializer : When_using_local_variable_query_argument_list { public With_xml_serializer() - : base(x => XmlSerializationHelper.CloneExpression(x, new[] { typeof(List) })) + : base(x => XmlSerializationHelper.CloneExpression(x, [typeof(List)])) { } } diff --git a/test/Remote.Linq.Tests/Serialization/VariableQueryArgument/When_using_local_variable_query_string_argument_list.cs b/test/Remote.Linq.Tests/Serialization/VariableQueryArgument/When_using_local_variable_query_string_argument_list.cs index f46b7fbb..324af1d0 100644 --- a/test/Remote.Linq.Tests/Serialization/VariableQueryArgument/When_using_local_variable_query_string_argument_list.cs +++ b/test/Remote.Linq.Tests/Serialization/VariableQueryArgument/When_using_local_variable_query_string_argument_list.cs @@ -22,7 +22,7 @@ public With_binary_formatter() public class With_data_contract_serializer : When_using_local_variable_query_string_argument_list { public With_data_contract_serializer() - : base(x => DataContractSerializationHelper.CloneExpression(x, new[] { typeof(List) })) + : base(x => DataContractSerializationHelper.CloneExpression(x, [typeof(List)])) { } } @@ -64,7 +64,7 @@ public With_protobuf_net_serializer() public class With_xml_serializer : When_using_local_variable_query_string_argument_list { public With_xml_serializer() - : base(x => XmlSerializationHelper.CloneExpression(x, new[] { typeof(List) })) + : base(x => XmlSerializationHelper.CloneExpression(x, [typeof(List)])) { } } diff --git a/test/Remote.Linq.Tests/TestData.cs b/test/Remote.Linq.Tests/TestData.cs index 1c11b757..6b09c0bc 100644 --- a/test/Remote.Linq.Tests/TestData.cs +++ b/test/Remote.Linq.Tests/TestData.cs @@ -147,13 +147,13 @@ public static IEnumerable TestValueLists private static object CreateArray(Type type, object item) { var toArrayMethod = typeof(Enumerable).GetMethod(nameof(Enumerable.ToArray), PublicStatic).MakeGenericMethod(type); - return toArrayMethod.Invoke(null, new[] { CreateEnumerable(type, item) }); + return toArrayMethod.Invoke(null, [CreateEnumerable(type, item)]); } private static object CreateList(Type type, object item) { var toListMethod = typeof(Enumerable).GetMethod(nameof(Enumerable.ToList), PublicStatic).MakeGenericMethod(type); - return toListMethod.Invoke(null, new[] { CreateEnumerable(type, item) }); + return toListMethod.Invoke(null, [CreateEnumerable(type, item)]); } private static object CreateEnumerable(Type type, object item) diff --git a/test/Remote.Linq.Tests/TestHelper.cs b/test/Remote.Linq.Tests/TestHelper.cs index 71dd5627..2ce3d26d 100644 --- a/test/Remote.Linq.Tests/TestHelper.cs +++ b/test/Remote.Linq.Tests/TestHelper.cs @@ -116,7 +116,7 @@ public static void ShouldBeNullable(this Type type) } public static object GetValueTaskResult(object valueTask, Type resultType) - => _getAsyncResultMethodInfo.MakeGenericMethod(resultType).Invoke(null, new[] { valueTask }); + => _getAsyncResultMethodInfo.MakeGenericMethod(resultType).Invoke(null, [valueTask]); public static Task GetValueTaskResultAsync(object valueTask, Type resultType) => Task.Run(() => GetValueTaskResult(valueTask, resultType));