Skip to content

Commit bc0b57a

Browse files
NH-3488 - Fix required by rebase, to be squashed
1 parent 25e1558 commit bc0b57a

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

src/NHibernate/Linq/Assignments.cs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Linq.Expressions;
66
using System.Reflection;
77
using NHibernate.Linq.Visitors;
8-
using Remotion.Linq.Utilities;
98

109
namespace NHibernate.Linq
1110
{
@@ -16,7 +15,7 @@ public abstract class Assignments
1615
}
1716

1817
/// <summary>
19-
/// Class to hold assigments used in updates and inserts
18+
/// Class to hold assignments used in updates and inserts
2019
/// </summary>
2120
/// <typeparam name="TInput">The type of the input.</typeparam>
2221
/// <typeparam name="TOutput">The type of the output.</typeparam>
@@ -33,14 +32,13 @@ public class Assignments<TInput, TOutput> : Assignments
3332
/// <returns></returns>
3433
public Assignments<TInput, TOutput> Set<TProp>(Expression<Func<TOutput, TProp>> property, Expression<Func<TInput, TProp>> expression)
3534
{
36-
ArgumentUtility.CheckNotNull("property", property);
37-
ArgumentUtility.CheckNotNull("expression", expression);
38-
var member = property.Body as MemberExpression;
35+
if (property == null)
36+
throw new ArgumentNullException(nameof(property));
37+
if (expression == null)
38+
throw new ArgumentNullException(nameof(expression));
3939
var param = property.Parameters.Single();
40-
if (member == null)
41-
{
42-
throw new ArgumentException("The property expression must refer to a property of " + param.Name + "("+ param.Type.Name + ")", "property");
43-
}
40+
var member = property.Body as MemberExpression ??
41+
throw new ArgumentException("The property expression must refer to a property of " + param.Name + "("+ param.Type.Name + ")", nameof(property));
4442
_sets.Add(new Assignment(member.GetMemberPath(), expression));
4543
return this;
4644
}
@@ -54,13 +52,11 @@ public Assignments<TInput, TOutput> Set<TProp>(Expression<Func<TOutput, TProp>>
5452
/// <returns></returns>
5553
public Assignments<TInput, TOutput> Set<TProp>(Expression<Func<TOutput, TProp>> property, TProp value)
5654
{
57-
ArgumentUtility.CheckNotNull("property", property);
58-
var member = property.Body as MemberExpression;
55+
if (property == null)
56+
throw new ArgumentNullException(nameof(property));
5957
var param = property.Parameters.Single();
60-
if (member == null)
61-
{
62-
throw new ArgumentException("The property expression must refer to a property of " + param.Name + "(" + param.Type.Name + ")", "property");
63-
}
58+
var member = property.Body as MemberExpression ??
59+
throw new ArgumentException("The property expression must refer to a property of " + param.Name + "(" + param.Type.Name + ")", nameof(property));
6460
_sets.Add(new Assignment(member.GetMemberPath(), Expression.Constant(value, typeof(TProp))));
6561
return this;
6662
}
@@ -76,8 +72,7 @@ public LambdaExpression ConvertToDictionaryExpression()
7672
foreach (var set in _sets)
7773
{
7874
var setter = set.Expression;
79-
var setterLambda = setter as LambdaExpression;
80-
if (setterLambda != null)
75+
if (setter is LambdaExpression setterLambda)
8176
{
8277
setter = setterLambda.Body.Replace(setterLambda.Parameters.First(), param);
8378
}
@@ -108,14 +103,11 @@ public LambdaExpression ConvertToDictionaryExpression()
108103

109104
public static Assignments<TInput, TOutput> FromExpression(Expression<Func<TInput, TOutput>> expression)
110105
{
111-
ArgumentUtility.CheckNotNull("expression", expression);
106+
if (expression == null)
107+
throw new ArgumentNullException(nameof(expression));
112108
var instance = new Assignments<TInput, TOutput>();
113-
var memberInitExpression = expression.Body as MemberInitExpression;
114-
115-
if (memberInitExpression == null)
116-
{
109+
var memberInitExpression = expression.Body as MemberInitExpression ??
117110
throw new ArgumentException("The expression must be member initialization, e.g. x => new Dog{Name = x.Name,Age = x.Age + 5}");
118-
}
119111

120112
AddSetsFromBindings(memberInitExpression.Bindings, instance, "", expression.Parameters);
121113

@@ -139,8 +131,8 @@ private static void AddSetsFromBindings(IEnumerable<MemberBinding> bindings, Ass
139131

140132
private static void AddSetsFromAssignment(MemberAssignment assignment, Assignments<TInput, TOutput> instance, string path, ReadOnlyCollection<ParameterExpression> parameters)
141133
{
142-
var memberInit = assignment.Expression as MemberInitExpression; // {Property=new Instance{SubProperty="Value"}}
143-
if (memberInit!=null)
134+
// {Property=new Instance{SubProperty="Value"}}
135+
if (assignment.Expression is MemberInitExpression memberInit)
144136
{
145137
AddSetsFromBindings(memberInit.Bindings, instance, path, parameters);
146138
}

src/NHibernate/Linq/InsertSyntax.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Linq;
33
using System.Linq.Expressions;
44
using Remotion.Linq;
5-
using Remotion.Linq.Utilities;
65

76
namespace NHibernate.Linq
87
{
@@ -23,7 +22,8 @@ internal InsertSyntax(IQueryable<TInput> query)
2322
/// <returns></returns>
2423
public int Into<TOutput>(Action<Assignments<TInput, TOutput>> assignmentActions)
2524
{
26-
ArgumentUtility.CheckNotNull("assignments", assignmentActions);
25+
if (assignmentActions == null)
26+
throw new ArgumentNullException(nameof(assignmentActions));
2727
var assignments = new Assignments<TInput, TOutput>();
2828
assignmentActions.Invoke(assignments);
2929
return InsertInto(_query, assignments);
@@ -43,8 +43,7 @@ public int As<TOutput>(Expression<Func<TInput, TOutput>> expression)
4343

4444
internal int InsertInto<TOutput>(IQueryable<TInput> query, Assignments<TInput, TOutput> assignments)
4545
{
46-
var nhQueryable = query as QueryableBase<TInput>;
47-
if (nhQueryable == null)
46+
var nhQueryable = query as QueryableBase<TInput> ??
4847
throw new NotSupportedException("Query needs to be of type QueryableBase<T>");
4948

5049
var provider = (DefaultQueryProvider)query.Provider;

src/NHibernate/Linq/UpdateSyntax.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public int Assign(Action<Assignments<T, T>> assignments, bool versioned = false)
3232
/// <summary>
3333
/// Specify the assignments and execute the update.
3434
/// </summary>
35-
/// <typeparam name="T"></typeparam>
36-
/// <param name="query">The query.</param>
3735
/// <param name="expression">The assignments expressed as a member initialization, e.g. x => new Dog{Name = x.Name,Age = x.Age + 5}.</param>
3836
/// <param name="versioned">if set to <c>true</c> [versioned].</param>
3937
/// <returns></returns>
@@ -44,10 +42,9 @@ public int As(Expression<Func<T, T>> expression, bool versioned = false)
4442
return ExecuteUpdate(versioned, assignments);
4543
}
4644

47-
private int ExecuteUpdate<T>(bool versioned, Assignments<T, T> assignments)
45+
private int ExecuteUpdate(bool versioned, Assignments<T, T> assignments)
4846
{
49-
var nhQueryable = _query as QueryableBase<T>;
50-
if (nhQueryable == null)
47+
var nhQueryable = _query as QueryableBase<T> ??
5148
throw new NotSupportedException("Query needs to be of type QueryableBase<T>");
5249

5350
var provider = (DefaultQueryProvider)nhQueryable.Provider;

0 commit comments

Comments
 (0)