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?