Skip to content

Commit

Permalink
Rename typos in method names, make all condition expression extension…
Browse files Browse the repository at this point in the history
…s internal, fix some code smells.
  • Loading branch information
jordimontana82 committed Mar 24, 2024
1 parent 02a2b4b commit 78ece40
Show file tree
Hide file tree
Showing 21 changed files with 97 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToBeginsWithExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace FakeXrmEasy.Query
/// <summary>
/// ConditionExpression Extensions
/// </summary>
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToBetweenExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
Expand All @@ -18,12 +18,12 @@ internal static Expression ToBetweenExpression(this TypedConditionExpression tc,
//Between the range...
var exp = Expression.And(
Expression.GreaterThanOrEqual(
tc.AttributeType.GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, value1),
TypeCastExpressions.GetAppropiateTypedValueAndType(value1, tc.AttributeType)),
tc.AttributeType.GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, value1),
TypeCastExpressionExtensions.GetAppropriateTypedValueAndType(value1, tc.AttributeType)),

Expression.LessThanOrEqual(
tc.AttributeType.GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, value2),
TypeCastExpressions.GetAppropiateTypedValueAndType(value2, tc.AttributeType)));
tc.AttributeType.GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, value2),
TypeCastExpressionExtensions.GetAppropriateTypedValueAndType(value2, tc.AttributeType)));


//and... attribute exists too
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
/// <summary>
/// Takes a condition expression which needs translating into a 'between two dates' expression and works out the relevant dates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToContainsExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToContainsValuesExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
var leftHandSideExpression = typeof(OptionSetValueCollection).GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, null);
var leftHandSideExpression = typeof(OptionSetValueCollection).GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, null);
var rightHandSideExpression = Expression.Constant(OptionSetValueCollectionExtensions.ConvertToHashSetOfInt(tc.CondExpression.Values, isOptionSetValueCollectionAccepted: false));

return Expression.AndAlso(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToEndsWithExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToEqualExpression(this TypedConditionExpression c, IXrmFakedContext context, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
Expand Down Expand Up @@ -42,18 +42,18 @@ internal static Expression ToEqualExpression(this TypedConditionExpression c, IX
if (unaryOperatorValue != null)
{
//c.Values empty in this case
var leftHandSideExpression = c.AttributeType.GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, unaryOperatorValue);
var leftHandSideExpression = c.AttributeType.GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, unaryOperatorValue);
var transformedExpression = leftHandSideExpression.TransformValueBasedOnOperator(c.CondExpression.Operator);

expOrValues = Expression.Equal(transformedExpression,
TypeCastExpressions.GetAppropiateTypedValueAndType(unaryOperatorValue, c.AttributeType));
TypeCastExpressionExtensions.GetAppropriateTypedValueAndType(unaryOperatorValue, c.AttributeType));
}
#if FAKE_XRM_EASY_9
else if (c.AttributeType == typeof(OptionSetValueCollection))
{
var conditionValue = c.GetSingleConditionValue();

var leftHandSideExpression = c.AttributeType.GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, conditionValue);
var leftHandSideExpression = c.AttributeType.GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, conditionValue);
var rightHandSideExpression = Expression.Constant(OptionSetValueCollectionExtensions.ConvertToHashSetOfInt(conditionValue, isOptionSetValueCollectionAccepted: false));

expOrValues = Expression.Equal(
Expand All @@ -65,12 +65,12 @@ internal static Expression ToEqualExpression(this TypedConditionExpression c, IX
{
foreach (object value in c.CondExpression.Values)
{
var leftHandSideExpression = c.AttributeType.GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, value);
var leftHandSideExpression = c.AttributeType.GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, value);
var transformedExpression = leftHandSideExpression.TransformValueBasedOnOperator(c.CondExpression.Operator);

expOrValues = Expression.Or(expOrValues,
Expression.Equal(transformedExpression,
TypeCastExpressions.GetAppropiateTypedValueAndType(value, c.AttributeType)
TypeCastExpressionExtensions.GetAppropriateTypedValueAndType(value, c.AttributeType)
.TransformValueBasedOnOperator(c.CondExpression.Operator)));


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToGreaterThanExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
Expand All @@ -20,7 +20,7 @@ internal static Expression ToGreaterThanExpression(this TypedConditionExpression
{
return tc.ToGreaterThanStringExpression(getAttributeValueExpr, containsAttributeExpr);
}
else if (TypeCastExpressions.GetAppropiateTypeForValue(c.Values[0]) == typeof(string))
else if (TypeCastExpressionExtensions.GetAppropriateTypeForValue(c.Values[0]) == typeof(string))
{
return tc.ToGreaterThanStringExpression(getAttributeValueExpr, containsAttributeExpr);
}
Expand All @@ -29,13 +29,13 @@ internal static Expression ToGreaterThanExpression(this TypedConditionExpression
BinaryExpression expOrValues = Expression.Or(Expression.Constant(false), Expression.Constant(false));
foreach (object value in c.Values)
{
var leftHandSideExpression = tc.AttributeType.GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, value);
var leftHandSideExpression = tc.AttributeType.GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, value);
var transformedExpression = leftHandSideExpression.TransformValueBasedOnOperator(tc.CondExpression.Operator);

expOrValues = Expression.Or(expOrValues,
Expression.GreaterThan(
transformedExpression,
TypeCastExpressions.GetAppropiateTypedValueAndType(value, tc.AttributeType).TransformValueBasedOnOperator(tc.CondExpression.Operator)));
TypeCastExpressionExtensions.GetAppropriateTypedValueAndType(value, tc.AttributeType).TransformValueBasedOnOperator(tc.CondExpression.Operator)));
}
return Expression.AndAlso(
containsAttributeExpr,
Expand All @@ -60,11 +60,11 @@ internal static Expression ToGreaterThanStringExpression(this TypedConditionExpr
BinaryExpression expOrValues = Expression.Or(Expression.Constant(false), Expression.Constant(false));
foreach (object value in c.Values)
{
var leftHandSideExpression = tc.AttributeType.GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, value);
var leftHandSideExpression = tc.AttributeType.GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, value);
var transformedExpression = leftHandSideExpression.TransformValueBasedOnOperator(tc.CondExpression.Operator);

var left = transformedExpression;
var right = TypeCastExpressions.GetAppropiateTypedValueAndType(value, tc.AttributeType).TransformValueBasedOnOperator(tc.CondExpression.Operator);
var right = TypeCastExpressionExtensions.GetAppropriateTypedValueAndType(value, tc.AttributeType).TransformValueBasedOnOperator(tc.CondExpression.Operator);

var methodCallExpr = left.ToCompareToExpression<string>(right);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToInExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
Expand All @@ -17,7 +17,7 @@ internal static Expression ToInExpression(this TypedConditionExpression tc, Expr
#if FAKE_XRM_EASY_9
if (tc.AttributeType?.IsOptionSetValueCollection() == true)
{
var leftHandSideExpression = tc.AttributeType.GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, null);
var leftHandSideExpression = tc.AttributeType.GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, null);
var rightHandSideExpression = Expression.Constant(OptionSetValueCollectionExtensions.ConvertToHashSetOfInt(c.Values, isOptionSetValueCollectionAccepted: false));

expOrValues = Expression.Equal(
Expand All @@ -32,8 +32,8 @@ internal static Expression ToInExpression(this TypedConditionExpression tc, Expr
if (!(value is Array))
{
expOrValues = Expression.Or(expOrValues, Expression.Equal(
tc.AttributeType.GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, value),
TypeCastExpressions.GetAppropiateTypedValueAndType(value, tc.AttributeType)));
tc.AttributeType.GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, value),
TypeCastExpressionExtensions.GetAppropriateTypedValueAndType(value, tc.AttributeType)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToLastXExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToLessThanExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
Expand All @@ -20,7 +20,7 @@ internal static Expression ToLessThanExpression(this TypedConditionExpression tc
{
return tc.ToLessThanStringExpression(getAttributeValueExpr, containsAttributeExpr);
}
else if (TypeCastExpressions.GetAppropiateTypeForValue(c.Values[0]) == typeof(string))
else if (TypeCastExpressionExtensions.GetAppropriateTypeForValue(c.Values[0]) == typeof(string))
{
return tc.ToLessThanStringExpression(getAttributeValueExpr, containsAttributeExpr);
}
Expand All @@ -29,13 +29,13 @@ internal static Expression ToLessThanExpression(this TypedConditionExpression tc
BinaryExpression expOrValues = Expression.Or(Expression.Constant(false), Expression.Constant(false));
foreach (object value in c.Values)
{
var leftHandSideExpression = tc.AttributeType.GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, value);
var leftHandSideExpression = tc.AttributeType.GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, value);
var transformedExpression = leftHandSideExpression.TransformValueBasedOnOperator(tc.CondExpression.Operator);

expOrValues = Expression.Or(expOrValues,
Expression.LessThan(
transformedExpression,
TypeCastExpressions.GetAppropiateTypedValueAndType(value, tc.AttributeType).TransformValueBasedOnOperator(tc.CondExpression.Operator)));
TypeCastExpressionExtensions.GetAppropriateTypedValueAndType(value, tc.AttributeType).TransformValueBasedOnOperator(tc.CondExpression.Operator)));
}
return Expression.AndAlso(
containsAttributeExpr,
Expand All @@ -59,10 +59,10 @@ internal static Expression ToLessThanStringExpression(this TypedConditionExpress
BinaryExpression expOrValues = Expression.Or(Expression.Constant(false), Expression.Constant(false));
foreach (object value in c.Values)
{
var leftHandSideExpression = tc.AttributeType.GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, value);
var leftHandSideExpression = tc.AttributeType.GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, value);
var transformedLeftHandSideExpression = leftHandSideExpression.TransformValueBasedOnOperator(tc.CondExpression.Operator);

var rightHandSideExpression = TypeCastExpressions.GetAppropiateTypedValueAndType(value, tc.AttributeType).TransformValueBasedOnOperator(tc.CondExpression.Operator);
var rightHandSideExpression = TypeCastExpressionExtensions.GetAppropriateTypedValueAndType(value, tc.AttributeType).TransformValueBasedOnOperator(tc.CondExpression.Operator);

var compareToMethodCall = transformedLeftHandSideExpression.ToCompareToExpression<string>(rightHandSideExpression);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToLikeExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
var c = tc.CondExpression;
BinaryExpression expOrValues = Expression.Or(Expression.Constant(false), Expression.Constant(false));
Expression convertedValueToStr = Expression.Convert(tc.AttributeType.GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, c.Values[0]), typeof(string));
Expression convertedValueToStr = Expression.Convert(tc.AttributeType.GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, c.Values[0]), typeof(string));

Expression convertedValueToStrAndToLower = convertedValueToStr.ToCaseInsensitiveExpression();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToNextXExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToNullExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static Expression ToOlderThanExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr)
{
Expand Down Expand Up @@ -55,8 +55,8 @@ internal static Expression ToOlderThanExpression(this TypedConditionExpression t
internal static Expression ToOlderThanExpression(this TypedConditionExpression tc, Expression getAttributeValueExpr, Expression containsAttributeExpr, DateTime olderThanDate)
{
var lessThanExpression = Expression.LessThan(
tc.AttributeType.GetAppropiateCastExpressionBasedOnType(getAttributeValueExpr, olderThanDate),
TypeCastExpressions.GetAppropiateTypedValueAndType(olderThanDate, tc.AttributeType));
tc.AttributeType.GetAppropriateCastExpressionBasedOnType(getAttributeValueExpr, olderThanDate),
TypeCastExpressionExtensions.GetAppropriateTypedValueAndType(olderThanDate, tc.AttributeType));

return Expression.AndAlso(containsAttributeExpr,
Expression.AndAlso(Expression.NotEqual(getAttributeValueExpr, Expression.Constant(null)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace FakeXrmEasy.Query
{
public static partial class ConditionExpressionExtensions
internal static partial class ConditionExpressionExtensions
{
internal static BinaryExpression TranslateMultipleConditionExpressions(this List<ConditionExpression> conditions, QueryExpression qe, IXrmFakedContext context, string sEntityName, LogicalOperator op, ParameterExpression entity, bool bIsOuter)
{
Expand Down
2 changes: 1 addition & 1 deletion src/FakeXrmEasy.Core/Query/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace FakeXrmEasy.Query
/// <summary>
///
/// </summary>
public static class ExpressionExtensions
internal static class ExpressionExtensions
{
internal static Expression TransformValueBasedOnOperator(this Expression input, ConditionOperator op)
{
Expand Down
Loading

0 comments on commit 78ece40

Please sign in to comment.