Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 917071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:09:03+00:00 2026-05-15T18:09:03+00:00

Before you start pointing me to duplicates just know that I have read nearly

  • 0

Before you start pointing me to duplicates just know that I have read nearly all the posts on SO about extension methods. I am just trying to play devil’s advocate for a minute to consider the alternative to my working opinion.

Recently I was working on a project and a need came up for a method to be a base of an interface. So I suggested we write an extension method and it was shot down. Saying it added complexity and harder to debug.

I of course argued and got on SO to find all the wonderful posts that show the many reasons why to use extension methods. Not to forget that a lot of the .net framework uses them. We eventually did not use it as I was overruled by the team.

But then it got me thinking, are there times when an extension method could be used but shouldn’t be?

I really couldn’t think of any but thought I would post here and see if anyone could think of any other reasons why they shouldn’t be used.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:09:03+00:00Added an answer on May 15, 2026 at 6:09 pm

    Any time you have a function which is “generally applicable” to an object of a certain type, regardless of its state, an extension method is a good choice.

    For example, today I added two new extension methods to our codebase:

    public static XElement ToXElement(this XmlElement element) { }
    
    public static XmlElement ToXmlElement(this XElement element) { }
    

    Both of these are, generally speaking, valid on the types they extend regardless of the state of the instance or where we are using it.

    If your method does not meet that criteria, it should probably be moved to a helper method closer to the context where the particular case is always true or easily checked.

    For example, a developer recently nominated this to be an extension method:

    public static bool ParseYesNoBool(this string input) { }
    

    There are two problems here: first, this will appear on all strings in the application, even though the number of strings which might ever be candidates for this case are very small. So we’ve broken the first rule, in that it is not useful regardless of state. Similarly, but second, the consumer of this functionality is limited to a single parser for one particular connector to an external system. So promoting implementation-specific functionality into the general-use namespace makes no sense. This was downgraded to a helper method in the parser.

    As far as readability and debugging, that is just incorrect for a developer of any reasonable skill level.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am using Mediainfo library in my C# project,before start invoking this dll,i just ran
before I start I want to point out that I tagged this question as
(Before I start, yes I have asked a similar question before; unfortunately due to
Before I start, I want to make it clear that my code is working
Before i start, i know the MD5 is compromised (collision attack and speed of
Am just started working for exporting excel spread sheet in PERL, Before start i
Before start let me tell my experience: I am experienced with C#.NET, web services,
I want to get one record before start date and end date DtpFrom means
I usually try to do TDD with not much analysis (no diagrams) before start
I am working on a Media up-loader which uploads images to Server. Before start

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.