Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend DynamicObject Wrapper to re-wrap sub-objects, but only anonymous ones #2535

Closed
iJungleboy opened this issue Sep 28, 2021 · 0 comments
Closed
Assignees

Comments

@iJungleboy
Copy link
Contributor

I'm submitting a ...
[x] change / feature request

...about
[x] Razor templating
[x] internals

Current behavior

Using AsDynamic(...) you can easily make any object dynamic. This is especially useful for anonymous types like this:

var x = AsDynamic(new {
  Something = "hello"
});

It's mainly used in these scenarios

  1. Passing back anonymous objects from functions outside of the main razor file
  2. Merging settings from predefined sources with settings from code
  3. Providing properties to sub-templates using Html.Partial("_onether.cshtml", new { Id = 27 }) which are then provided on a dynamic DynamicModel object

The challenge appears when we have sub-objects, like this

var x = AsDynamic(new {
  Guid = new Guid(),
  Sub = new {
    Subproperty = "hello"
  },
  List = new List<string>(),
  Arr = new string[0]
});

In these cases, it's sometimes useful to re-wrap the sub-objects, and sometimes it's a problem. For example, a Guid shouldn't rewrap, because it becomes harder to use, but other anonymous object should be re-wrapped again.

Your environment

  • 2sxc version(s): 12.04
@iJungleboy iJungleboy self-assigned this Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant