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

Access properties of dictionary value #582

Open
antonGritsenko opened this issue Aug 1, 2023 · 1 comment
Open

Access properties of dictionary value #582

antonGritsenko opened this issue Aug 1, 2023 · 1 comment

Comments

@antonGritsenko
Copy link

I have some complex class with properties of Dictionary type:

var some  = new ComplexObject { Id = 1, AdditionalData = new Dictionary<string, SubObject>{ {"Test", new SubObject{ Property1 = "Some" }  } };

var parser = new FluidParser();
if (_parser.TryParse(template, out var fluidTemplate, out var error))
  {
      var context = new TemplateContext(some);

      return fluidTemplate.Render(context);
  }
  else
  {
      throw new Exception(error);
  }

How can I access the inner SubObject? I've tried template like this:

{% if AdditionalData["Test"] %} 
there is additional data: {{ AdditionalData.size}}
{% if AdditionalData["Test"].Property1 %}
Property1: {{ AdditionalData["Test"].Property1 }}
{% endif %}
{% endif %}

It rendered as:

there is additional data: 1

so AdditionalData["Test"].Property1 is nil.

Is this by design?

@antonGritsenko
Copy link
Author

OK, get it at the end, you must use options.MemberAccessStrategy.Register explicitly for all inner classes,

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