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 1095635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:09:24+00:00 2026-05-17T00:09:24+00:00

In our ASP.NET MVC project, we have an HtmlHelper extension method to generate a

  • 0

In our ASP.NET MVC project, we have an HtmlHelper extension method to generate a static google map.

public static MvcHtmlString StaticMap(this HtmlHelper helper, string address, string alt, int width, int height, int zoom)
{
    var src = new Uri("http://maps.google.com/maps/api/staticmap?markers=size:mid|color:red|{0}&zoom={1}&size={2}x{3}&maptype=roadmap&sensor=false".FormatInvariant(Uri.EscapeUriString(address), zoom, width, height));
    var href = new Uri("http://maps.google.com/maps?f=q&source=s_q&hl=en&q={0}".FormatInvariant(Uri.EscapeUriString(address)));

    var img = new TagBuilder("img");
    img.MergeAttribute("src", src.ToString());
    img.MergeAttribute("alt", alt);

    var link = new TagBuilder("a") { InnerHtml = img.ToString() };
    link.MergeAttribute("href", href.ToString());

    return MvcHtmlString.Create(link.ToString());
}

For this new project, we are also trying to keep all code analysis rule on. Now, obviously, Visual Studio Code analysis states that we should remove the helper parameter because it is not being used.

That made me wondering if an extension method should always make use of the extended object and if it does not, then maybe it shouldn’t be an extension method.

Does someone has a link to a guideline or an explication that would help me decide?

  • 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-17T00:09:25+00:00Added an answer on May 17, 2026 at 12:09 am

    The distinction to the using code between an extension method and a static method is purely conceptual; one relates to an object of a particular type in the same manner as an instance method, and the other does not.

    This being so, I would ask the question, “does considering this operation to be upon an HtmlHelper object make sense?”. This in turn becomes “does considering HtmlHelper objects to provide this operation, make sense?”. If I answered “yes” to that question, I would consider an extension method to be a reasonable approach, whether I used an HtmlHelper object or not. Conversely, if I answered “no” to that question, I would consider an extension method to be an ill-advised approach, even if the HtmlHelper object did get used.

    The code-analysis does a better job at analysing code-use than concepts, so it gives a warning here. It’s imperfect, and indeed there are other cases where ignoring a parameter is reasonable (maintaining compatibility either with a previous version or an interface being the best case, “reserved for future use” being a more arguable case).

    It’s notable that in some languages (well, C++ for one) you can leave a parameter name out precisely to mean “this parameter is in the signature, but won’t be used”. I quite like this, as it is true that generally not using a parameter is a bad sign, so it’s nice to have a means to indicate you were deliberate in this.

    Edit:

    Another justification. Imagine you had an extension method on a class that did use the relevant object. Now imagine you realise you can make it more reliable, efficient, or otherwise “better” for some value of “better” by re-writing in such a way that you are no longer using the object. Should you not be allowed to keep the extension method now that you’ve improved it? Should you be forced to stay with the inferior version?

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

Sidebar

Related Questions

In our ASP.NET MVC project we have a Strings.resx file and the accompanying autogenerated
I am using T4MVC in our ASP.NET MVC project. I have a statement like
We have a ASP.Net MVC project that runs fine on our developer machines. When
We have CC.NET setup on our ASP.NET app. When we build the project, the
We are trying to write Unit Tests in our ASP.Net MVC project. Some of
I have an existing ASP.Net MVC project that is using entities / repositories in
I've written some custom model binders (implementing IModelBinder) in our ASP.NET MVC application. I'm
Our workstations are running 64-bit Vista, and the production servers for our ASP.NET MVC
My team is considering building our next web app using the ASP.NET MVC framework.
In my current project we are testing our ASP.NET GUI using WatiN and Mbunit

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.