-
-
Notifications
You must be signed in to change notification settings - Fork 244
LINQ methods respect the configured casing #968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
LINQ methods respect the configured casing #968
Conversation
…itive was set to true
StefH
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
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