Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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