Skip to content

Commit

Permalink
style: change method call expression style
Browse files Browse the repository at this point in the history
  • Loading branch information
saeed committed May 28, 2024
1 parent cca39c3 commit 41f6d9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/SpelParser/SpelGrammerCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ private MethodCallExpression CreateCallCompareToMethodExpression(FieldContext fi
var constant = Convert.ChangeType(Enum.Parse(fieldType, GetString(constantContext), true), underlyingType);
fieldExpression = Expression.Convert(fieldExpression, underlyingType);
fieldType = underlyingType;
constantExpression = Expression.Constant(constant);
constantExpression = Expression.Constant(constant);
}
else
{
constantExpression = CreateValueExpression(fieldType, constantContext);
}

return Expression.Call(fieldExpression, fieldType.GetMethod("CompareTo", [fieldType])!, constantExpression);
return Expression.Call(fieldExpression, fieldType.GetMethod(nameof(IComparable.CompareTo), [fieldType])!, constantExpression);
}

private Expression CreateValueExpression(Type fieldExpression, ConstantContext constantContext)
Expand All @@ -113,10 +113,9 @@ private Expression CreateValueExpression(Type fieldExpression, ConstantContext c
if (fieldExpression == typeof(string))
return constantExpression;

if (fieldExpression.GetMethod("Parse", [typeof(string)]) != null)
return Expression.Call(fieldExpression, "Parse", Type.EmptyTypes, constantExpression);
var methodCallExpression = fieldExpression.GetMethod("Parse", [typeof(string)]) ?? throw new ArgumentException("Unknown type", fieldExpression.ToString());

throw new ArgumentException("Unknown type", fieldExpression.ToString());
return Expression.Call(methodCallExpression, constantExpression);
}

public Expression<Func<T, bool>> CreateFunc(string input)
Expand Down
4 changes: 2 additions & 2 deletions src/SpelParser/SpelParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<PackageVersion>1.0.101</PackageVersion>
<PackageVersion>1.0.2</PackageVersion>
<PackageId>SpelParser</PackageId>
<Version>1.0.101</Version>
<Version>1.0.2</Version>
<Authors>Saeed Bolhasani</Authors>
<PackageDescription>Convert string to expression</PackageDescription>
<RepositoryUrl>https://github.com/SaeedBolhasani/SpelParser</RepositoryUrl>
Expand Down

0 comments on commit 41f6d9f

Please sign in to comment.