Skip to content

Commit

Permalink
introduced stylecop
Browse files Browse the repository at this point in the history
  • Loading branch information
6bee committed Mar 16, 2018
1 parent 19e0bf5 commit 55db884
Show file tree
Hide file tree
Showing 120 changed files with 868 additions and 874 deletions.
8 changes: 8 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
<VersionPrefix>5.7.0</VersionPrefix>
<Authors>Christof Senn</Authors>
</PropertyGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)StyleNoDoc.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
Expand Down
10 changes: 10 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>
<ItemGroup>
<AdditionalFiles Include="$(MSBuildThisFileDirectory)Stylecop.json">
<Link>Stylecop.json</Link>
</AdditionalFiles>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta006">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
11 changes: 6 additions & 5 deletions GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using System.Reflection;
// Copyright (c) Christof Senn. All rights reserved. See license.txt in the project root for license information.

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]


[assembly: AssemblyVersion("5.0.0.0")]
26 changes: 26 additions & 0 deletions Style.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Remote.Linq" Description=" " ToolsVersion="14.0">
<Include Path="MinimumRecommendedRules.ruleset" Action="Default" />
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CS1701" Action="Info" />
</Rules>
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Features" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Features">
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1101" Action="None" />
<Rule Id="SA1127" Action="None" />
<Rule Id="SA1133" Action="None" />
<Rule Id="SA1201" Action="None" />
<Rule Id="SA1202" Action="None" />
<Rule Id="SA1204" Action="None" />
<Rule Id="SA1205" Action="None" />
<Rule Id="SA1306" Action="None" />
<Rule Id="SA1309" Action="None" />
<Rule Id="SA1310" Action="None" />
<Rule Id="SA1512" Action="None" />
<Rule Id="SA1602" Action="Info" />
<Rule Id="SA1611" Action="Info" />
<Rule Id="SA1615" Action="Info" />
<Rule Id="SA1618" Action="Info" />
</Rules>
</RuleSet>
8 changes: 8 additions & 0 deletions StyleNoDoc.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Remote.Linq.NoDoc" Description=" " ToolsVersion="14.0">
<Include Path="Style.ruleset" Action="Default" />
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1601" Action="None" />
</Rules>
</RuleSet>
16 changes: 16 additions & 0 deletions Stylecop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"settings": {
"orderingRules": {
"systemUsingDirectivesFirst": false
},
"documentationRules": {
"companyName": "Christof Senn",
"copyrightText": "Copyright (c) {companyName}. All rights reserved. See {licenseFile} in the project root for license information.",
"xmlHeader": false,
"variables": {
"licenseFile": "license.txt"
},
"fileNamingConvention": "metadata"
}
}
}
12 changes: 8 additions & 4 deletions src/Remote.Linq.EntityFramework/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static class ExpressionExtensions
/// <param name="dbContext">Instance of <see cref="DbContext"/> to get the <see cref="DbSet{T}"/></param>
/// <param name="typeResolver">Optional instance of <see cref="ITypeResolver"/> to be used to translate <see cref="Aqua.TypeSystem.TypeInfo"/> into <see cref="Type"/> objects</param>
/// <param name="mapper">Optional instance of <see cref="IDynamicObjectMapper"/></param>
/// <param name="setTypeInformation">Function to define whether to add type information</param>
/// <returns>A new instance <see cref="ExpressionExecutionContext" /></returns>
public static ExpressionExecutionContext EntityFrameworkExecutor(this Expression expression, DbContext dbContext, ITypeResolver typeResolver = null, IDynamicObjectMapper mapper = null, Func<Type, bool> setTypeInformation = null)
=> new ExpressionExecutionContext(new EntityFrameworkExpressionExecutor(dbContext, typeResolver, mapper, setTypeInformation), expression);
Expand All @@ -32,6 +33,7 @@ public static ExpressionExecutionContext EntityFrameworkExecutor(this Expression
/// <param name="queryableProvider">Delegate to provide <see cref="IQueryable"/> instances for given <see cref="Type"/>s</param>
/// <param name="typeResolver">Optional instance of <see cref="ITypeResolver"/> to be used to translate <see cref="Aqua.TypeSystem.TypeInfo"/> into <see cref="Type"/> objects</param>
/// <param name="mapper">Optional instance of <see cref="IDynamicObjectMapper"/></param>
/// <param name="setTypeInformation">Function to define whether to add type information</param>
/// <returns>A new instance <see cref="ExpressionExecutionContext" /></returns>
public static ExpressionExecutionContext EntityFrameworkExecutor(this Expression expression, Func<Type, IQueryable> queryableProvider, ITypeResolver typeResolver = null, IDynamicObjectMapper mapper = null, Func<Type, bool> setTypeInformation = null)
=> new ExpressionExecutionContext(new EntityFrameworkExpressionExecutor(queryableProvider, typeResolver, mapper, setTypeInformation), expression);
Expand All @@ -43,6 +45,7 @@ public static ExpressionExecutionContext EntityFrameworkExecutor(this Expression
/// <param name="dbContext">Instance of <see cref="DbContext"/> to get the <see cref="DbSet{T}"/></param>
/// <param name="typeResolver">Optional instance of <see cref="ITypeResolver"/> to be used to translate <see cref="Aqua.TypeSystem.TypeInfo"/> into <see cref="Type"/> objects</param>
/// <param name="mapper">Optional instance of <see cref="IDynamicObjectMapper"/></param>
/// <param name="setTypeInformation">Function to define whether to add type information</param>
/// <returns>The mapped result of the query execution</returns>
public static IEnumerable<DynamicObject> ExecuteWithEntityFramework(this Expression expression, DbContext dbContext, ITypeResolver typeResolver = null, IDynamicObjectMapper mapper = null, Func<Type, bool> setTypeInformation = null)
=> new EntityFrameworkExpressionExecutor(dbContext, typeResolver, mapper, setTypeInformation).Execute(expression);
Expand All @@ -54,25 +57,26 @@ public static IEnumerable<DynamicObject> ExecuteWithEntityFramework(this Express
/// <param name="queryableProvider">Delegate to provide <see cref="IQueryable"/> instances for given <see cref="Type"/>s</param>
/// <param name="typeResolver">Optional instance of <see cref="ITypeResolver"/> to be used to translate <see cref="Aqua.TypeSystem.TypeInfo"/> into <see cref="Type"/> objects</param>
/// <param name="mapper">Optional instance of <see cref="IDynamicObjectMapper"/></param>
/// <param name="setTypeInformation">Function to define whether to add type information</param>
/// <returns>The mapped result of the query execution</returns>
public static IEnumerable<DynamicObject> ExecuteWithEntityFramework(this Expression expression, Func<Type, IQueryable> queryableProvider, ITypeResolver typeResolver = null, IDynamicObjectMapper mapper = null, Func<Type, bool> setTypeInformation = null)
=> new EntityFrameworkExpressionExecutor(queryableProvider, typeResolver, mapper, setTypeInformation).Execute(expression);

/// <summary>
/// Prepares the query <see cref="Expression"/> to be able to be executed. <para/>
/// Prepares the query <see cref="Expression"/> to be able to be executed. <para/>
/// Use this method if you wan to execute the <see cref="System.Linq.Expressions.Expression"/> and map the raw result yourself.
/// </summary>
/// <param name="expression">The <see cref="Expression"/> to be executed</param>
/// <param name="dbContext">Instance of <see cref="DbContext"/> to get the <see cref="DbSet{}"/></param>
/// <param name="dbContext">Instance of <see cref="DbContext"/> to get the <see cref="DbSet{T}"/></param>
/// <param name="typeResolver">Optional instance of <see cref="ITypeResolver"/> to be used to translate <see cref="Aqua.TypeSystem.TypeInfo"/> into <see cref="Type"/> objects</param>
/// <returns>A <see cref="System.Linq.Expressions.Expression"/> ready for execution</returns>
[Obsolete("This method is being removed in a future version. Inherit from Remote.Linq.EntityFramework.EntityFrameworkExpressionExecutor or use expression.EntityFrameworkExecutor(..).With(customstrategy).Execute() instead.", false)]
public static System.Linq.Expressions.Expression PrepareForExecutionWithEntityFramework(this Expression expression, DbContext dbContext, ITypeResolver typeResolver = null)
=> new EntityFrameworkExpressionExecutor(dbContext, typeResolver).PrepareForExecution(expression);

/// <summary>
/// Prepares the query <see cref="Expression"/> to be able to be executed. <para/>
/// Use this method if you wan to execute the <see cref="System.Linq.Expressions.Expression"/> and map the raw result yourself. <para/>
/// Prepares the query <see cref="Expression"/> to be able to be executed. <para/>
/// Use this method if you wan to execute the <see cref="System.Linq.Expressions.Expression"/> and map the raw result yourself. <para/>
/// Please note that Inlude operation has no effect if using non-generic method <see cref="IQueryable" /> <see cref="DbContext" />.Get(<see cref="Type" />) as queryableProvider.
/// Better use generic version instead.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion src/Remote.Linq.EntityFramework/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Runtime.CompilerServices;
// Copyright (c) Christof Senn. All rights reserved. See license.txt in the project root for license information.

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Remote.Linq.EntityFramework.Test")]
9 changes: 4 additions & 5 deletions src/Remote.Linq.EntityFramework/SystemExpressionReWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ namespace Remote.Linq.EntityFramework
internal static class SystemExpressionReWriter
{
/// <summary>
/// Replaces parameterized constructor calls for <see cref="VariableQueryArgument{1}"/> with type initializer
/// Replaces parameterized constructor calls for <see cref="VariableQueryArgument{T}"/> with type initializer
/// </summary>
internal static Expression ReplaceParameterizedConstructorCallsForVariableQueryArguments(this Expression expression)
{
return new ReWriter().Run(expression);
}
=> new ReWriter().Run(expression);

private sealed class ReWriter : ExpressionVisitorBase
{
Expand Down Expand Up @@ -52,13 +50,14 @@ private Expression Visit(NewExpression node)
node.Arguments.Any())
{
var valueArgument = node.Arguments.First();

// Note: optional second type argument is omitted since it would not be supported by EF anyway
return Expression.MemberInit(
Expression.New(type),
Expression.Bind(type.GetProperty(nameof(VariableQueryArgument.Value)), valueArgument));
}

return base.VisitNew(node);
return VisitNew(node);
}
}
}
Expand Down
Loading

0 comments on commit 55db884

Please sign in to comment.