M
Marcel Müller
I need to find sub strings case insensitive inside lambda expressions.
Something like:
..Where(obj => obj.StringAttribute.CaseInsensitiveContains(somestring))
There is no case insensitive Contains in framework 3.5, but the class
CompareInfo provides a useful IndexOf:
var ci = CultureInfo.CurrentCulture.CompareInfo;
..Where(obj => ci.IndexOf(obj.StringAttribute, somestring,
CompareOptions.IgnoreCase) >= 0);
Unfortunately the IndexOf method is not marked as thread safe an the
expression tree my be evaluated in background by another thread.
I could lookup the current culture on every comparison, but this has the
side effect of taking the CultureInfo of some worker thread rather than
the owner of the query. Furthermore I am unsure whether calling
CultureInfo.CurrentCulture.CompareInfo some thousand times in a loop is
a good advise. And last but not least I am not able to use a custom
CultureInfo which is not the current CultureInfo of a thread this way.
Is there a way out of this dead end?
Marcel
Something like:
..Where(obj => obj.StringAttribute.CaseInsensitiveContains(somestring))
There is no case insensitive Contains in framework 3.5, but the class
CompareInfo provides a useful IndexOf:
var ci = CultureInfo.CurrentCulture.CompareInfo;
..Where(obj => ci.IndexOf(obj.StringAttribute, somestring,
CompareOptions.IgnoreCase) >= 0);
Unfortunately the IndexOf method is not marked as thread safe an the
expression tree my be evaluated in background by another thread.
I could lookup the current culture on every comparison, but this has the
side effect of taking the CultureInfo of some worker thread rather than
the owner of the query. Furthermore I am unsure whether calling
CultureInfo.CurrentCulture.CompareInfo some thousand times in a loop is
a good advise. And last but not least I am not able to use a custom
CultureInfo which is not the current CultureInfo of a thread this way.
Is there a way out of this dead end?
Marcel