2

I did a reflection with ILSpy of System.Web.MVC.dll and found out the following code:

public static RouteValueDictionary AnonymousObjectToHtmlAttributes(object htmlAttributes)
    {
        return HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
    }

Can someone help me to understand what exactly is happening here? This should lead to a StackOverflow Exception, but doesn't.

Arthur Castro
  • 610
  • 6
  • 18
  • What makes you think it would throw a `StackOverflowException`? The method is calling the `AnonymousObjectToHtmlAttributes()` method of the `HtmlHelper` class –  May 15 '16 at 03:59
  • @Stephen Muecke It's calling itself. – Arthur Castro May 15 '16 at 05:20
  • 2
    Where? This is the [source code](https://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Mvc/HtmlHelper.cs) for `HtmlHelper`. The method you have shown is not code in the `HtmlHelper` class. Its in another class which is calling the `AnonymousObjectToHtmlAttributes(htmlAttributes)` static method of `HtmlHelper`. They just happen to have the same name. –  May 15 '16 at 05:33
  • @StephenMuecke Thanks! – Arthur Castro May 15 '16 at 15:34

1 Answers1

2

As Stephen Muecke commented above, the method AnonymousObjectToHtmlAttributes from System.Web.MVC.HtmlHelper is calling a method with the same name but from System.Web.WebPages.Html.HtmlHelper.

The ILSpy is not explicitly about that. I needed to hover the class to show from where it was coming:

ILSpy

I'm not the first with that doubt, it's a common mistake to be made, I believe.

Community
  • 1
  • 1
Arthur Castro
  • 610
  • 6
  • 18