scriban icon indicating copy to clipboard operation
scriban copied to clipboard

Object properties do not respect MemberRenamerDelegate in ScriptObject

Open Esperadoce opened this issue 9 months ago • 1 comments

The PrepareMembers method in the constructor of TypedObjectAccessor is currently using the MemberRenamerDelegate from the TemplateContext, which has a default value.

This results in the custom MemberRenamerDelegate specified in the ScriptObject.Import method not being used. So In my case I have to set this information twice in the ScriptObject.Import and in the TemplateContext.

Is this the intended behavior, or is it a mistake? I couldn't find any information about it in the documentation.

Esperadoce avatar Mar 03 '25 15:03 Esperadoce

Is this the intended behavior, or is it a mistake?

Yes, this is the correct behavior.

TypedObjectAccessor is created when a .NET objects is dynamically accessed through the scripting engine. In that case, it needs to fetch a member renamer from the TemplateContext.

ScriptObject.Import can be created outside of a TemplateContext, outside of an evaluation context, so it has to be specified there if necessary.

I couldn't find any information about it in the documentation.

This is explained here https://github.com/scriban/scriban/blob/master/doc/runtime.md#member-renamer

xoofx avatar Mar 05 '25 10:03 xoofx