From a47ffacb0a9fd119552a36b1de6f3eabed444e50 Mon Sep 17 00:00:00 2001 From: saeed Date: Tue, 28 May 2024 23:13:39 +0330 Subject: [PATCH] style: change method call expression style --- src/SpelParser/SpelGrammerCompiler.cs | 9 ++++----- src/SpelParser/SpelParser.csproj | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/SpelParser/SpelGrammerCompiler.cs b/src/SpelParser/SpelGrammerCompiler.cs index b3138f0..0c9cd5e 100644 --- a/src/SpelParser/SpelGrammerCompiler.cs +++ b/src/SpelParser/SpelGrammerCompiler.cs @@ -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) @@ -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> CreateFunc(string input) diff --git a/src/SpelParser/SpelParser.csproj b/src/SpelParser/SpelParser.csproj index eb2d89b..c9dd834 100644 --- a/src/SpelParser/SpelParser.csproj +++ b/src/SpelParser/SpelParser.csproj @@ -3,9 +3,9 @@ net8.0 enable - 1.0.101 + 1.0.201 SpelParser - 1.0.101 + 1.0.201 Saeed Bolhasani Convert string to expression https://github.com/SaeedBolhasani/SpelParser