NancyFx/Nancy — pull request #536 by Crisfole (2012-03-02 02:35:12+00:00)
Title: Razor anonymous model spike

We bumped into this when trying to do the following in Razor:

@Model.Name.First

with the following model:

new { Name = new { First = "Chris" } }

The problem *didn't* happen when the object was singly-nested and the problem *didn't* happen if we turned our object into an expando (fully and recursively) first. This is a known limitation of the Razor view engine because the Razor View engine transforms all Views into code within its own assembly. Since C# anonymous objects' members are all `internal` they are not accessible outside the assembly. Your `GetExpandoObject` method in `DefaultViewFactory` was not taking into account the nested object issue.

There is a known problem with the current solution (the failing test introduced by d39c5817):

I couldn't figure out a good way to unobtrusively `GetSafeModel` on Models that have properties that are anonymous and need to be "Expandoed"). Reasons this is hard:
a. Recursing arbitrarily deep in an object could easily result in stackoverflow exceptions
b. Recursing could find a circular reference. (Thus causing #1)
c. Recursing arbitrarily could take a long time, seriously slowing down Nancy's DefaultViewFactory
2. The failing test I've committed demonstrates #1