LINQ methods respect the configured casing#968
LINQ methods respect the configured casing#968victorr99 wants to merge 2 commits intozzzprojects:masterfrom
Conversation
…itive was set to true
StefH
left a comment
There was a problem hiding this comment.
And will this not break any code where a Class has a property max?
Like
public class X
{
public string max { get ; set; }
public string MAX { get ; set; }
}Maybe add a unit test for this.
| return true; | ||
| } | ||
|
|
||
| private bool CanonicalContains(string[] haystack, ref string needle) |
There was a problem hiding this comment.
no need to use ref
just do:
if (_parsingConfig.IsCaseSensitive)
{
return haystack.Contains(needle);
}
return haystack.Any(s => string.Equals(s, value, StringComparison.OrdinalIgnoreCase));There was a problem hiding this comment.
I've changed the method to just Contains. It indeed works without using ref, so I've removed that.
I've tried to add some unit tests with a max property. Is this what you had in mind?
- Tests added for a model with a max property - CanonicalContains is now just Contains without ref string needle
|
@StefH can you have a look again at the PR? |
|
@StefH any updates? |
|
I'm still thinking about backward compatibility... |
|
The only compatability issue I can think of is that a custom enumerable object is being used which specifies public class CustomEnumerable<T> : IEnumerable<T>
{
public int Max { get; set; }
public int Min()
{
}
}The public class CustomEnumerable<T>(IEnumerable<T> inner) : IEnumerable<T>
{
public T Max { get; set; }
public DateTime Min()
{
return default;
}
public IEnumerator<T> GetEnumerator()
{
return inner.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
var parameter = Expression.Parameter(typeof(CustomEnumerable<int>), "list");
var parser = new ExpressionParser(
[parameter],
"list.Min()",
[],
new ParsingConfig { IsCaseSensitive = false });
var expression = parser.Parse(typeof(int));
var lambda = Expression.Lambda<Func<CustomEnumerable<int>, int>>(expression, parameter);
var method = lambda.CompileFast();
Console.WriteLine(method(new CustomEnumerable<int>([15])));So, I assume fixing it the right way introduces another backward compatability issue, or the CustomEnumerable example is a new bug. By the way, you asked for extra tests which covers the |
|
@StefH can we finish this PR? the review is taking almost 2 months now |
The ExpressionParser was updated with a new method allowing case insensitive compares whenever this was configured in the ParserConfig.
The method
CanonicalContainsperforms a case insensitive check wheneverIsCaseSensitivewas set to false. It also updates the providedneedleparameter to the actual found value. Thus a match onmaxwill be translated toMax.This fixes issue #967