Skip to content

Commit

Permalink
Fix some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
axelheer committed Nov 16, 2023
1 parent b7e43ab commit ac699e0
Show file tree
Hide file tree
Showing 23 changed files with 297 additions and 291 deletions.
27 changes: 16 additions & 11 deletions nein-linq.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29123.88
# Visual Studio Version 17
VisualStudioVersion = 17.8.34309.116
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{62384529-4A89-45AA-9241-6C41D736333C}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -11,24 +10,30 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DC57719B-6A66-4F54-B935-C206C91DA09D}"
ProjectSection(SolutionItems) = preProject
src\.globalconfig = src\.globalconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeinLinq", "src\NeinLinq\NeinLinq.csproj", "{620F44CA-BD35-43C4-B449-B12C87942FE2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeinLinq", "src\NeinLinq\NeinLinq.csproj", "{620F44CA-BD35-43C4-B449-B12C87942FE2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeinLinq.Async", "src\NeinLinq.Async\NeinLinq.Async.csproj", "{8A2507C3-E583-432C-8613-E673DE93E799}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeinLinq.Async", "src\NeinLinq.Async\NeinLinq.Async.csproj", "{8A2507C3-E583-432C-8613-E673DE93E799}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeinLinq.EntityFramework", "src\NeinLinq.EntityFramework\NeinLinq.EntityFramework.csproj", "{34E61C0E-4109-426C-B7AE-B7024A815DF2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeinLinq.EntityFramework", "src\NeinLinq.EntityFramework\NeinLinq.EntityFramework.csproj", "{34E61C0E-4109-426C-B7AE-B7024A815DF2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeinLinq.EntityFrameworkCore", "src\NeinLinq.EntityFrameworkCore\NeinLinq.EntityFrameworkCore.csproj", "{8A92E5D9-60E5-4683-802F-6745EF459ECF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeinLinq.EntityFrameworkCore", "src\NeinLinq.EntityFrameworkCore\NeinLinq.EntityFrameworkCore.csproj", "{8A92E5D9-60E5-4683-802F-6745EF459ECF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{F79B7C9C-7883-4D8C-AF41-1E155CAF01A9}"
ProjectSection(SolutionItems) = preProject
test\.globalconfig = test\.globalconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeinLinq.Tests", "test\NeinLinq.Tests\NeinLinq.Tests.csproj", "{9D6EE79A-734A-4212-A802-1CA2D9746C82}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeinLinq.Tests", "test\NeinLinq.Tests\NeinLinq.Tests.csproj", "{9D6EE79A-734A-4212-A802-1CA2D9746C82}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeinLinq.Async.Tests", "test\NeinLinq.Async.Tests\NeinLinq.Async.Tests.csproj", "{95AE475D-3FCD-477E-AFCE-18B4A61E0290}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeinLinq.Async.Tests", "test\NeinLinq.Async.Tests\NeinLinq.Async.Tests.csproj", "{95AE475D-3FCD-477E-AFCE-18B4A61E0290}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeinLinq.EntityFramework.Tests", "test\NeinLinq.EntityFramework.Tests\NeinLinq.EntityFramework.Tests.csproj", "{E5C860D8-5879-4291-9C5A-D415982D4EB8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeinLinq.EntityFramework.Tests", "test\NeinLinq.EntityFramework.Tests\NeinLinq.EntityFramework.Tests.csproj", "{E5C860D8-5879-4291-9C5A-D415982D4EB8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeinLinq.EntityFrameworkCore.Tests", "test\NeinLinq.EntityFrameworkCore.Tests\NeinLinq.EntityFrameworkCore.Tests.csproj", "{DA287DB2-E87C-4EDB-A070-F695B2038E7E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeinLinq.EntityFrameworkCore.Tests", "test\NeinLinq.EntityFrameworkCore.Tests\NeinLinq.EntityFrameworkCore.Tests.csproj", "{DA287DB2-E87C-4EDB-A070-F695B2038E7E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 0 additions & 2 deletions src/.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ is_global = true
# Use 'ArgumentNullException.ThrowIfNull' instead
dotnet_diagnostic.CA1510.severity = none

# Change return type of method
dotnet_diagnostic.CA1859.severity = none
20 changes: 10 additions & 10 deletions src/NeinLinq.Async/DynamicAsyncQueryable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ public static IOrderedAsyncQueryable<T> ThenBy<T>(this IOrderedAsyncQueryable<T>
CreateAsyncOrderClause(target, query.Expression, selector, false, descending));
}

private static Expression CreateAsyncOrderClause(ParameterExpression target,
Expression expression,
string selector,
bool initial,
bool descending)
private static MethodCallExpression CreateAsyncOrderClause(ParameterExpression target,
Expression expression,
string selector,
bool initial,
bool descending)
{
var keySelector = Expression.Lambda(DynamicExpression.CreateMemberAccess(target, selector), target);

Expand All @@ -126,17 +126,17 @@ private static Expression CreateAsyncOrderClause(ParameterExpression target,
: (descending ? nameof(AsyncQueryable.ThenByDescending)
: nameof(AsyncQueryable.ThenBy));

return Expression.Call(typeof(AsyncQueryable), method, new[] { target.Type, keySelector.ReturnType },
return Expression.Call(typeof(AsyncQueryable), method, [target.Type, keySelector.ReturnType],
expression, Expression.Quote(keySelector));
}

private static Expression CreateAsyncWhereClause(ParameterExpression target,
Expression expression,
Expression comparison)
private static MethodCallExpression CreateAsyncWhereClause(ParameterExpression target,
Expression expression,
Expression comparison)
{
var predicate = Expression.Lambda(comparison, target);

return Expression.Call(typeof(AsyncQueryable), nameof(AsyncQueryable.Where), new[] { target.Type },
return Expression.Call(typeof(AsyncQueryable), nameof(AsyncQueryable.Where), [target.Type],
expression, Expression.Quote(predicate));
}
}
4 changes: 2 additions & 2 deletions src/NeinLinq/DynamicExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ private static Expression CreateConstant(ParameterExpression target,

var expression = (Expression)target;

var ordinalParse = underlyingType.GetMethod("Parse", new[] { typeof(string) });
var ordinalParse = underlyingType.GetMethod("Parse", [typeof(string)]);
if (ordinalParse is not null)
expression = Expression.Call(ordinalParse, target);

var cultureParse = underlyingType.GetMethod("Parse", new[] { typeof(string), typeof(IFormatProvider) });
var cultureParse = underlyingType.GetMethod("Parse", [typeof(string), typeof(IFormatProvider)]);
if (cultureParse is not null)
expression = Expression.Call(cultureParse, target, format);

Expand Down
20 changes: 10 additions & 10 deletions src/NeinLinq/DynamicQueryable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ public static IOrderedQueryable<T> ThenBy<T>(this IOrderedQueryable<T> query,
CreateOrderClause(target, query.Expression, selector, false, descending));
}

private static Expression CreateOrderClause(ParameterExpression target,
Expression expression,
string selector,
bool initial,
bool descending)
private static MethodCallExpression CreateOrderClause(ParameterExpression target,
Expression expression,
string selector,
bool initial,
bool descending)
{
var keySelector = Expression.Lambda(DynamicExpression.CreateMemberAccess(target, selector), target);

Expand All @@ -230,17 +230,17 @@ private static Expression CreateOrderClause(ParameterExpression target,
: (descending ? nameof(Queryable.ThenByDescending)
: nameof(Queryable.ThenBy));

return Expression.Call(typeof(Queryable), method, new[] { target.Type, keySelector.ReturnType },
return Expression.Call(typeof(Queryable), method, [target.Type, keySelector.ReturnType],
expression, Expression.Quote(keySelector));
}

private static Expression CreateWhereClause(ParameterExpression target,
Expression expression,
Expression comparison)
private static MethodCallExpression CreateWhereClause(ParameterExpression target,
Expression expression,
Expression comparison)
{
var predicate = Expression.Lambda(comparison, target);

return Expression.Call(typeof(Queryable), nameof(Queryable.Where), new[] { target.Type },
return Expression.Call(typeof(Queryable), nameof(Queryable.Where), [target.Type],
expression, Expression.Quote(predicate));
}
}
2 changes: 1 addition & 1 deletion src/NeinLinq/InjectLambdaSignature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public InjectLambdaSignature(PropertyInfo property)
throw new InvalidOperationException($"Property {property.Name} has no declaring type.");

genericArguments = Type.EmptyTypes;
parameterTypes = new[] { property.DeclaringType };
parameterTypes = [property.DeclaringType];
returnType = property.PropertyType;
isStatic = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/NeinLinq/NullsafeQueryRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static bool IsSafe(Expression? expression)
: null;
}

private static Expression? CollectionFallback(Type definition, Type type)
private static UnaryExpression? CollectionFallback(Type definition, Type type)
{
var collection = definition.MakeGenericType(type.GetGenericArguments());

Expand Down
6 changes: 0 additions & 6 deletions test/.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,5 @@ dotnet_diagnostic.CA1812.severity = none
# Avoid unsealed internal classes
dotnet_diagnostic.CA1852.severity = none

# Change return type of method
dotnet_diagnostic.CA1859.severity = none

# Prefer 'static readonly' fields
dotnet_diagnostic.CA1861.severity = none

# Do not directly await a Task
dotnet_diagnostic.CA2007.severity = none
34 changes: 18 additions & 16 deletions test/NeinLinq.Async.Tests/DynamicAsyncQueryableTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Globalization;
using Xunit;

#pragma warning disable CA1861

namespace NeinLinq.Tests;

[CLSCompliant(false)]
Expand Down Expand Up @@ -77,9 +79,9 @@ public async Task OperatorWhere_NullValue_ComparesAsync(DynamicCompare compariso
[Fact]
public async Task MethodWhere_Compares()
{
var actual = await CreateQuery<IAsyncQueryable<Model>>().Where("Name", "Contains", "b").Select(d => d.Id).ToArrayAsync();
var actual = await CreateQuery<IAsyncQueryable<Model>>().Where("Name", "Contains", "b").Select(d => d.Id).ToListAsync();

Assert.Equal(new[] { 2, 5, 8 }, actual);
Assert.Equal([2, 5, 8], actual);
}

[Fact]
Expand Down Expand Up @@ -120,27 +122,27 @@ public async Task OrderByThenBy_ComparesAsync()
var one = CreateQuery<IAsyncQueryable<Model>>().OrderBy("Name.Length").ThenBy("Name", true);
var two = CreateQuery<IAsyncQueryable<Model>>().OrderBy("Name.Length", true).ThenBy("Name");

var oneResult = await one.Select(d => d.Id).ToArrayAsync();
var twoResult = await two.Select(d => d.Id).ToArrayAsync();
var oneResult = await one.Select(d => d.Id).ToListAsync();
var twoResult = await two.Select(d => d.Id).ToListAsync();

Assert.Equal(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 }, oneResult);
Assert.Equal(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, twoResult);
Assert.Equal([9, 8, 7, 6, 5, 4, 3, 2, 1], oneResult);
Assert.Equal([1, 2, 3, 4, 5, 6, 7, 8, 9], twoResult);
}

private static T CreateQuery<T>()
{
var data = new[]
{
new Model { Id = 1, Name = "aaaa", Number = 11.11m },
new Model { Id = 2, Name = "bbbb", Number = 22.22m },
new Model { Id = 3, Name = "cccc", Number = 33.33m },
new Model { Id = 4, Name = "aaa", Number = 111.111m },
new Model { Id = 5, Name = "bbb", Number = 222.222m },
new Model { Id = 6, Name = "ccc", Number = 333.333m },
new Model { Id = 7, Name = "aa", Number = 1111.1111m },
new Model { Id = 8, Name = "bb", Number = 2222.2222m },
new Model { Id = 9, Name = "cc", Number = 3333.3333m }
};
new Model { Id = 1, Name = "aaaa", Number = 11.11m },
new Model { Id = 2, Name = "bbbb", Number = 22.22m },
new Model { Id = 3, Name = "cccc", Number = 33.33m },
new Model { Id = 4, Name = "aaa", Number = 111.111m },
new Model { Id = 5, Name = "bbb", Number = 222.222m },
new Model { Id = 6, Name = "ccc", Number = 333.333m },
new Model { Id = 7, Name = "aa", Number = 1111.1111m },
new Model { Id = 8, Name = "bb", Number = 2222.2222m },
new Model { Id = 9, Name = "cc", Number = 3333.3333m }
};

return (T)data.ToAsyncEnumerable().AsAsyncQueryable();
}
Expand Down
40 changes: 20 additions & 20 deletions test/NeinLinq.EntityFramework.Tests/EntityFrameworkFakeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task ExecuteAsync_ExecutesAsync()
var query = CreateQuery().DbRewrite(rewriter);

var result = await ((IDbAsyncQueryProvider)query.Provider).ExecuteAsync(
Expression.Call(typeof(Queryable), nameof(Queryable.Count), new[] { typeof(Model) }, query.Expression),
Expression.Call(typeof(Queryable), nameof(Queryable.Count), [typeof(Model)], query.Expression),
default
);

Expand All @@ -85,25 +85,25 @@ private static IQueryable<Model> CreateQuery()
{
var data = new[]
{
new Model
{
Id = 1,
Name = "Asdf",
Number = 123.45f
},
new Model
{
Id = 2,
Name = "Qwer",
Number = 67.89f
},
new Model
{
Id = 3,
Name = "Narf",
Number = 3.14f
}
};
new Model
{
Id = 1,
Name = "Asdf",
Number = 123.45f
},
new Model
{
Id = 2,
Name = "Qwer",
Number = 67.89f
},
new Model
{
Id = 3,
Name = "Narf",
Number = 3.14f
}
};

return data.AsQueryable();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,25 @@ private static IQueryable<Model> CreateQuery()
{
var data = new[]
{
new Model
{
Id = 1,
Name = "Asdf",
Number = 123.45f
},
new Model
{
Id = 2,
Name = "Qwer",
Number = 67.89f
},
new Model
{
Id = 3,
Name = "Narf",
Number = 3.14f
}
};
new Model
{
Id = 1,
Name = "Asdf",
Number = 123.45f
},
new Model
{
Id = 2,
Name = "Qwer",
Number = 67.89f
},
new Model
{
Id = 3,
Name = "Narf",
Number = 3.14f
}
};

return data.AsQueryable();
}
Expand Down
26 changes: 14 additions & 12 deletions test/NeinLinq.Tests/DynamicQueryTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Globalization;
using Xunit;

#pragma warning disable CA1861

namespace NeinLinq.Tests;

[CLSCompliant(false)]
Expand Down Expand Up @@ -73,9 +75,9 @@ public void MethodCreatePredicate_Compares()
{
var predicate = DynamicQuery.CreatePredicate<Model>("Name", "Contains", "b");

var result = CreateQuery().Where(predicate).Select(d => d.Id).ToArray();
var result = CreateQuery().Where(predicate).Select(d => d.Id).ToList();

Assert.Equal(new[] { 2, 5, 8 }, result);
Assert.Equal([2, 5, 8], result);
}

[Fact]
Expand Down Expand Up @@ -125,16 +127,16 @@ private static IQueryable<Model> CreateQuery()
{
var data = new[]
{
new Model { Id = 1, Name = "aaaa", Number = 11.11m, Reference = Guid.NewGuid(), OneTwo = OneTwo.Undefined, OneTwoMaybe = OneTwo.Two },
new Model { Id = 2, Name = "bbbb", Number = 22.22m, Reference = Guid.NewGuid(), OneTwo = OneTwo.Undefined, OneTwoMaybe = OneTwo.Two},
new Model { Id = 3, Name = "cccc", Number = 33.33m, Reference = Guid.NewGuid(), OneTwo = OneTwo.Undefined, OneTwoMaybe = null},
new Model { Id = 4, Name = "aaa", Number = 111.111m, Reference = Guid.NewGuid(), OneTwo = OneTwo.One, OneTwoMaybe = OneTwo.Undefined },
new Model { Id = 5, Name = "bbb", Number = 222.222m, Reference = Guid.NewGuid(), OneTwo = OneTwo.One, OneTwoMaybe = OneTwo.Undefined },
new Model { Id = 6, Name = "ccc", Number = 333.333m, Reference = Guid.NewGuid(), OneTwo = OneTwo.One, OneTwoMaybe = null },
new Model { Id = 7, Name = "aa", Number = 1111.1111m, Reference = Guid.NewGuid(), OneTwo = OneTwo.Two, OneTwoMaybe = OneTwo.One},
new Model { Id = 8, Name = "bb", Number = 2222.2222m, Reference = Guid.NewGuid(), OneTwo = OneTwo.Two, OneTwoMaybe = OneTwo.One },
new Model { Id = 9, Name = "cc", Number = 3333.3333m, Reference = Guid.NewGuid(), OneTwo = OneTwo.Two, OneTwoMaybe = null }
};
new Model { Id = 1, Name = "aaaa", Number = 11.11m, Reference = Guid.NewGuid(), OneTwo = OneTwo.Undefined, OneTwoMaybe = OneTwo.Two },
new Model { Id = 2, Name = "bbbb", Number = 22.22m, Reference = Guid.NewGuid(), OneTwo = OneTwo.Undefined, OneTwoMaybe = OneTwo.Two},
new Model { Id = 3, Name = "cccc", Number = 33.33m, Reference = Guid.NewGuid(), OneTwo = OneTwo.Undefined, OneTwoMaybe = null},
new Model { Id = 4, Name = "aaa", Number = 111.111m, Reference = Guid.NewGuid(), OneTwo = OneTwo.One, OneTwoMaybe = OneTwo.Undefined },
new Model { Id = 5, Name = "bbb", Number = 222.222m, Reference = Guid.NewGuid(), OneTwo = OneTwo.One, OneTwoMaybe = OneTwo.Undefined },
new Model { Id = 6, Name = "ccc", Number = 333.333m, Reference = Guid.NewGuid(), OneTwo = OneTwo.One, OneTwoMaybe = null },
new Model { Id = 7, Name = "aa", Number = 1111.1111m, Reference = Guid.NewGuid(), OneTwo = OneTwo.Two, OneTwoMaybe = OneTwo.One},
new Model { Id = 8, Name = "bb", Number = 2222.2222m, Reference = Guid.NewGuid(), OneTwo = OneTwo.Two, OneTwoMaybe = OneTwo.One },
new Model { Id = 9, Name = "cc", Number = 3333.3333m, Reference = Guid.NewGuid(), OneTwo = OneTwo.Two, OneTwoMaybe = null }
};

return data.AsQueryable();
}
Expand Down
Loading

0 comments on commit ac699e0

Please sign in to comment.