Access properties of dictionary value
antonGritsenko opened this issue · comments
Anton commented
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?
Anton commented
OK, get it at the end, you must use options.MemberAccessStrategy.Register
explicitly for all inner classes,