Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. another extension

another extension

Scheduled Pinned Locked Moved The Weird and The Wonderful
rubycomhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VallarasuS
    wrote on last edited by
    #1

    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

    Z Richard DeemingR 2 Replies Last reply
    0
    • V VallarasuS

      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

      Z Offline
      Z Offline
      zenwalker1985
      wrote on last edited by
      #2

      He/She probably wanted to do some coding ;)

      My cUr10U5 w0rlD

      1 Reply Last reply
      0
      • V VallarasuS

        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

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        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

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        V 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          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

          V Offline
          V Offline
          VallarasuS
          wrote on last edited by
          #4

          You are right! Shame on me... ;P :laugh:

          Regards Vallarasu S | BreakingDotNet.blogspot.com

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups