String.Contains
optionally takes a StringComparison
enum (eg StringComparison.OrdinalIgnoreCase
). I keep forgetting to specify IgnoreCase
, so I want to mark that method as [Obsolete]
so I see it in Warnings
so I remember to specify the kind of StringComparison
.
I'm open to other solutions too, like doing something to "hide" that method and prevent it from being called. The ideal solution doesn't involve Roslyn analyzers though, as I'm using F#.
This solution is interesting, but obviously not ideal.
I would use an Extension Method. Just put it somewhere that's available to all your code, and declare it directly in the System namespace. (I'm not fluent in F#, but this should work.)
namespace System
type String with
member CaselessContains(str) = String.Contains(str, StringComparison.OrdinalIgnoreCase)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.