another extension
-
We have too many extension methods spread across our project, I was organizing those methods with the rule of thumb 'as long as they reside in same namespace class name won't matter', by placing string, enumerable and other extension members to appropriate classes, to avoid members being duplicated. (Even I repeated things and thats why the organizing.. ;P ) And then I've unearthed this gem.
public static class ExtensionMethods { public static bool Contains(this string source, string toCheck, StringComparison comp) { return source.IndexOf(toCheck, comp) >= 0; } …
I found two odd things with this implementation, - first string already contains an overload "Contains(string toCheck, StringComparison comp)", I "honestly" don’t know if it makes any difference. - second the usage this where the compiler failed, and used in many places the same way!
if (ExtensionMethods.Contains(item.Caption, "Some text here", StringComparison.OrdinalIgnoreCase)) { ... ... }
I don’t know if the author learned the purpose of existence of extension methods! And need someone to fix things! Edit : there is no such overload, it's the same extension on intellisence ;P
Regards Vallarasu S | BreakingDotNet.blogspot.com
-
We have too many extension methods spread across our project, I was organizing those methods with the rule of thumb 'as long as they reside in same namespace class name won't matter', by placing string, enumerable and other extension members to appropriate classes, to avoid members being duplicated. (Even I repeated things and thats why the organizing.. ;P ) And then I've unearthed this gem.
public static class ExtensionMethods { public static bool Contains(this string source, string toCheck, StringComparison comp) { return source.IndexOf(toCheck, comp) >= 0; } …
I found two odd things with this implementation, - first string already contains an overload "Contains(string toCheck, StringComparison comp)", I "honestly" don’t know if it makes any difference. - second the usage this where the compiler failed, and used in many places the same way!
if (ExtensionMethods.Contains(item.Caption, "Some text here", StringComparison.OrdinalIgnoreCase)) { ... ... }
I don’t know if the author learned the purpose of existence of extension methods! And need someone to fix things! Edit : there is no such overload, it's the same extension on intellisence ;P
Regards Vallarasu S | BreakingDotNet.blogspot.com
He/She probably wanted to do some coding ;)
-
We have too many extension methods spread across our project, I was organizing those methods with the rule of thumb 'as long as they reside in same namespace class name won't matter', by placing string, enumerable and other extension members to appropriate classes, to avoid members being duplicated. (Even I repeated things and thats why the organizing.. ;P ) And then I've unearthed this gem.
public static class ExtensionMethods { public static bool Contains(this string source, string toCheck, StringComparison comp) { return source.IndexOf(toCheck, comp) >= 0; } …
I found two odd things with this implementation, - first string already contains an overload "Contains(string toCheck, StringComparison comp)", I "honestly" don’t know if it makes any difference. - second the usage this where the compiler failed, and used in many places the same way!
if (ExtensionMethods.Contains(item.Caption, "Some text here", StringComparison.OrdinalIgnoreCase)) { ... ... }
I don’t know if the author learned the purpose of existence of extension methods! And need someone to fix things! Edit : there is no such overload, it's the same extension on intellisence ;P
Regards Vallarasu S | BreakingDotNet.blogspot.com
VallarasuS wrote:
string already contains an overload "Contains(string toCheck, StringComparison comp)"
Does it? Which version of .NET are you using? The only overload listed on MSDN is
string.Contains(string)
. http://msdn.microsoft.com/en-us/library/dy85x1sa.aspx[^] Are you sure you're not getting confused by seeing the extension method in the intellisense list? ;P
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
VallarasuS wrote:
string already contains an overload "Contains(string toCheck, StringComparison comp)"
Does it? Which version of .NET are you using? The only overload listed on MSDN is
string.Contains(string)
. http://msdn.microsoft.com/en-us/library/dy85x1sa.aspx[^] Are you sure you're not getting confused by seeing the extension method in the intellisense list? ;P
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
You are right! Shame on me... ;P :laugh:
Regards Vallarasu S | BreakingDotNet.blogspot.com