Skip to content

Commit

Permalink
Transformed to Visual Studio 2017 format.
Browse files Browse the repository at this point in the history
Only .NET Standard 1.0 is supported now.
Version 1.2.0.
  • Loading branch information
IharBury committed Mar 11, 2017
1 parent 10f0204 commit 1e3a549
Show file tree
Hide file tree
Showing 24 changed files with 88 additions and 919 deletions.
13 changes: 5 additions & 8 deletions IharBury.Expressions.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{17E67771-410B-4CCB-ABF7-30E89B868247}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CC2F5DE4-0070-486A-B269-DEE912BDA490}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IharBury.Expressions", "src\IharBury.Expressions\IharBury.Expressions.xproj", "{8A77AEDF-DF6A-4DB9-8499-DF0B89250E67}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2E635B3B-8AF5-475D-8E28-5BEE24E6663D}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IharBury.Expressions.Tests", "test\IharBury.Expressions.Tests\IharBury.Expressions.Tests.xproj", "{43627114-3681-41BD-99EC-DCA4CBB68602}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IharBury.Expressions", "src\IharBury.Expressions\IharBury.Expressions.csproj", "{8A77AEDF-DF6A-4DB9-8499-DF0B89250E67}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2E635B3B-8AF5-475D-8E28-5BEE24E6663D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IharBury.Expressions.Tests", "test\IharBury.Expressions.Tests\IharBury.Expressions.Tests.csproj", "{43627114-3681-41BD-99EC-DCA4CBB68602}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
6 changes: 0 additions & 6 deletions global.json

This file was deleted.

4 changes: 2 additions & 2 deletions pack.cmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@echo off

call test.cmd
call test.cmd Release

pushd src\IharBury.Expressions
dotnet pack --configuration Release
dotnet pack --configuration Release --include-symbols
popd
27 changes: 11 additions & 16 deletions src/IharBury.Expressions/BooleanExpressions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace IharBury.Expressions
Expand All @@ -22,7 +21,7 @@ public static Expression<Func<bool>> CombineViaAndAlso(IEnumerable<Expression<Fu
if (expressions == null)
throw new ArgumentNullException(nameof(expressions));

return (Expression<Func<bool>>)Combine(expressions.CovariantCast(), Expression.AndAlso);
return (Expression<Func<bool>>)Combine(expressions, Expression.AndAlso);
}

/// <summary>
Expand All @@ -38,7 +37,7 @@ public static Expression<Func<T1, bool>> CombineViaAndAlso<T1>(
if (expressions == null)
throw new ArgumentNullException(nameof(expressions));

return (Expression<Func<T1, bool>>)Combine(expressions.CovariantCast(), Expression.AndAlso);
return (Expression<Func<T1, bool>>)Combine(expressions, Expression.AndAlso);
}

/// <summary>
Expand All @@ -54,7 +53,7 @@ public static Expression<Func<T1, T2, bool>> CombineViaAndAlso<T1, T2>(
if (expressions == null)
throw new ArgumentNullException(nameof(expressions));

return (Expression<Func<T1, T2, bool>>)Combine(expressions.CovariantCast(), Expression.AndAlso);
return (Expression<Func<T1, T2, bool>>)Combine(expressions, Expression.AndAlso);
}

/// <summary>
Expand All @@ -70,7 +69,7 @@ public static Expression<Func<T1, T2, T3, bool>> CombineViaAndAlso<T1, T2, T3>(
if (expressions == null)
throw new ArgumentNullException(nameof(expressions));

return (Expression<Func<T1, T2, T3, bool>>)Combine(expressions.CovariantCast(), Expression.AndAlso);
return (Expression<Func<T1, T2, T3, bool>>)Combine(expressions, Expression.AndAlso);
}

/// <summary>
Expand All @@ -86,10 +85,9 @@ public static Expression<Func<T1, T2, T3, T4, bool>> CombineViaAndAlso<T1, T2, T
if (expressions == null)
throw new ArgumentNullException(nameof(expressions));

return (Expression<Func<T1, T2, T3, T4, bool>>)Combine(expressions.CovariantCast(), Expression.AndAlso);
return (Expression<Func<T1, T2, T3, T4, bool>>)Combine(expressions, Expression.AndAlso);
}

#if !NET35 && !NET35_CLIENT
/// <summary>
/// Combines boolean expressions with same parameters via AndAlso
/// (logical "and" that evaluates the second argument only when the first one is true).
Expand Down Expand Up @@ -304,7 +302,6 @@ public static Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
expressions,
Expression.AndAlso);
}
#endif

/// <summary>
/// Combines boolean expressions without parameters via OrElse
Expand All @@ -318,7 +315,7 @@ public static Expression<Func<bool>> CombineViaOrElse(IEnumerable<Expression<Fun
if (expressions == null)
throw new ArgumentNullException(nameof(expressions));

return (Expression<Func<bool>>)Combine(expressions.CovariantCast(), Expression.OrElse);
return (Expression<Func<bool>>)Combine(expressions, Expression.OrElse);
}

/// <summary>
Expand All @@ -334,7 +331,7 @@ public static Expression<Func<T1, bool>> CombineViaOrElse<T1>(
if (expressions == null)
throw new ArgumentNullException(nameof(expressions));

return (Expression<Func<T1, bool>>)Combine(expressions.CovariantCast(), Expression.OrElse);
return (Expression<Func<T1, bool>>)Combine(expressions, Expression.OrElse);
}

/// <summary>
Expand All @@ -350,7 +347,7 @@ public static Expression<Func<T1, T2, bool>> CombineViaOrElse<T1, T2>(
if (expressions == null)
throw new ArgumentNullException(nameof(expressions));

return (Expression<Func<T1, T2, bool>>)Combine(expressions.CovariantCast(), Expression.OrElse);
return (Expression<Func<T1, T2, bool>>)Combine(expressions, Expression.OrElse);
}

/// <summary>
Expand All @@ -366,7 +363,7 @@ public static Expression<Func<T1, T2, T3, bool>> CombineViaOrElse<T1, T2, T3>(
if (expressions == null)
throw new ArgumentNullException(nameof(expressions));

return (Expression<Func<T1, T2, T3, bool>>)Combine(expressions.CovariantCast(), Expression.OrElse);
return (Expression<Func<T1, T2, T3, bool>>)Combine(expressions, Expression.OrElse);
}

/// <summary>
Expand All @@ -382,10 +379,9 @@ public static Expression<Func<T1, T2, T3, T4, bool>> CombineViaOrElse<T1, T2, T3
if (expressions == null)
throw new ArgumentNullException(nameof(expressions));

return (Expression<Func<T1, T2, T3, T4, bool>>)Combine(expressions.CovariantCast(), Expression.OrElse);
return (Expression<Func<T1, T2, T3, T4, bool>>)Combine(expressions, Expression.OrElse);
}

#if !NET35 && !NET35_CLIENT
/// <summary>
/// Combines boolean expressions with same parameters via OrElse
/// (logical "or" that evaluates the second argument only when the first one is false).
Expand Down Expand Up @@ -598,7 +594,6 @@ public static Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
expressions,
Expression.OrElse);
}
#endif

private static LambdaExpression Combine(
IEnumerable<LambdaExpression> expressions,
Expand Down Expand Up @@ -647,7 +642,7 @@ private static LambdaExpression Combine(
}
if (firstExpression == null)
throw new ArgumentException("Expression list is empty.", nameof(expressions));
return resultBody.CreateLambda(resultParameters);
return Expression.Lambda(resultBody, resultParameters);
}
}
}
125 changes: 0 additions & 125 deletions src/IharBury.Expressions/CompatibilityExtensions.cs

This file was deleted.

28 changes: 22 additions & 6 deletions src/IharBury.Expressions/ExpressionExpander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,26 @@ namespace IharBury.Expressions
{
internal sealed class ExpressionExpander : ExpressionVisitor
{
private static readonly MethodInfo MethodInfoCreateDelegateMethod = typeof(MethodInfo)
.FindMethod("CreateDelegate", typeof(Type), typeof(object));
private static readonly MethodInfo DelegateCreateDelegateMethod = typeof(Delegate)
.FindMethod("CreateDelegate", typeof(Type), typeof(object), typeof(MethodInfo));
private static readonly MethodInfo MethodInfoCreateDelegateMethod =
FindMethod(typeof(MethodInfo), "CreateDelegate", typeof(Type), typeof(object));
private static readonly MethodInfo DelegateCreateDelegateMethod =
FindMethod(typeof(Delegate), "CreateDelegate", typeof(Type), typeof(object), typeof(MethodInfo));

private static MethodInfo FindMethod(Type type, string name, params Type[] parameterTypes)
{
if (type == null)
throw new ArgumentNullException(nameof(type));
if (string.IsNullOrEmpty(name))
throw new ArgumentException($"string.{nameof(string.IsNullOrEmpty)}({nameof(name)}name)", nameof(name));
if (parameterTypes == null)
throw new ArgumentNullException(nameof(parameterTypes));

return type
.GetTypeInfo()
.GetDeclaredMethods(name)
.SingleOrDefault(method =>
method.GetParameters().Select(parameter => parameter.ParameterType).SequenceEqual(parameterTypes));
}

private ExpressionExpander() { }

Expand Down Expand Up @@ -52,7 +68,7 @@ private static bool IsCompileMethod(MethodInfo method)
throw new ArgumentNullException(nameof(method));

return (method.DeclaringType != null) &&
method.DeclaringType.GetIsConstructedGenericType() &&
method.DeclaringType.IsConstructedGenericType &&
(method.DeclaringType.GetGenericTypeDefinition() == typeof(Expression<>)) &&
(method.Name == nameof(Expression<Func<object>>.Compile));
}
Expand Down Expand Up @@ -91,7 +107,7 @@ protected override Expression VisitMethodCall(MethodCallExpression node)
}

if ((baseResult.Method.DeclaringType != null) &&
(baseResult.Method.DeclaringType.GetBaseType() == typeof(MulticastDelegate)) &&
(baseResult.Method.DeclaringType.GetTypeInfo().BaseType == typeof(MulticastDelegate)) &&
(baseResult.Method.Name == nameof(Action.Invoke)) &&
(baseResult.Object != null) &&
(baseResult.Object.NodeType == ExpressionType.Call))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ protected override Expression VisitParameter(ParameterExpression node)
return base.VisitParameter(node);
}

#if NET35 || NET35_CLIENT
protected override Expression VisitLambda(LambdaExpression node)
#else
protected override Expression VisitLambda<T>(Expression<T> node)
#endif
{
allowedParameters.AddRange(node.Parameters);
var result = base.VisitLambda(node);
Expand Down
4 changes: 0 additions & 4 deletions src/IharBury.Expressions/ExpressionParameterSubstitutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ protected override Expression VisitParameter(ParameterExpression node)
base.VisitParameter(node);
}

#if NET35 || NET35_CLIENT
protected override Expression VisitLambda(LambdaExpression node)
#else
protected override Expression VisitLambda<T>(Expression<T> node)
#endif
{
var newParameters = new List<ParameterExpression>(node.Parameters.Count);

Expand Down
Loading

0 comments on commit 1e3a549

Please sign in to comment.