Skip to content

Commit

Permalink
added symbol check when checking for identifier (#728)
Browse files Browse the repository at this point in the history
* added symbol check

* added test case for preference

* simplified code for type prioritization
  • Loading branch information
abbasc52 committed Aug 13, 2023
1 parent 0b23f3b commit 06d4110
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -931,10 +931,20 @@ private Expression ParseIdentifier()

var isValidKeyWord = _keywordsHelper.TryGetValue(_textParser.CurrentToken.Text, out var value);

var extraCondition = !_parsingConfig.PrioritizePropertyOrFieldOverTheType ||
(_parsingConfig.PrioritizePropertyOrFieldOverTheType && !(value is Type && _it != null && FindPropertyOrField(_it.Type, _textParser.CurrentToken.Text, false) != null));

bool shouldPrioritizeType = true;

if (_parsingConfig.PrioritizePropertyOrFieldOverTheType && value is Type)
{
bool isPropertyOrField = _it != null && FindPropertyOrField(_it.Type, _textParser.CurrentToken.Text, false) != null;
bool hasSymbol = _symbols.ContainsKey(_textParser.CurrentToken.Text);
if (isPropertyOrField || hasSymbol)
{
shouldPrioritizeType = false;
}
}

if (isValidKeyWord && extraCondition)
if (isValidKeyWord && shouldPrioritizeType)
{
if (value is Type typeValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,14 @@ public void Parse_NullableShouldReturnNullable(string expression, object resultT
[InlineData("Company.Equals(null, null)", "Equals(null, null)")]
[InlineData("MainCompany.Name", "company.MainCompany.Name")]
[InlineData("Name", "company.Name")]
[InlineData("company.Name","company.Name")]
[InlineData("DateTime", "company.DateTime")]
public void Parse_When_PrioritizePropertyOrFieldOverTheType_IsTrue(string expression, string result)
{
// Arrange
var config = new ParsingConfig
{
IsCaseSensitive = true,
CustomTypeProvider = _dynamicTypeProviderMock.Object
};
ParameterExpression[] parameters = { ParameterExpressionHelper.CreateParameterExpression(typeof(Company), "company") };
Expand Down

0 comments on commit 06d4110

Please sign in to comment.