We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Clarification on Contextual Object Member Access

Hi All,

I am seeking clarification on how the statement “Inside a data band body, the object is resolved to the innermost iteration variable.” from https://docs.aspose.com/words/net/using-contextual-object-member-access/ works when a property on the object in the for each has the same name as a data source passed into

public bool BuildReport(Document document, object[] dataSources, string[] dataSourceNames);

I have a template that has a data source called “Record” and a for each item where the Item object also as a property called “Record”.

e.g. <<foreach [Items]>><<[Role?.Label]>> <<[Record?.Label]>><</foreach>>

Based statement above from the documentation, I would have expected the <<[Record?.Label]>> to display the Label of the Record in the item but when I build the template, the LINQ Engine tries accessing the Data Source with the name “Record”.

Which behavior is expected: That “Record” resolves to the iteration variable or to the data source name?

Note: I know that I can work around this by either qualifying the iteration variable or changing the name of the Data Source but this means that all datasource names functionally become reserved words and/or I can not use Contextual Object Member Access because the introduction of any non-unique Data Source name will break existing templates.

@steven.towler

This is an expected behavior. Otherwise, it would be impossible to access data sources or variables named the same as contextual object members. That is why, resolution to a member of a contextual object is performed as a last resort while parsing template expressions.

@ivan.lyagin Thank you for the confirmation. I half expected this to be the case.

It might be worth improving the contextual object members documentation cover specifically the scenario where a member has the same name as a data source or a variable in the document being processed. Or possibly just that you can access data sources within a foreach when using contextual object members.

Cheers,
Steve

@steven.towler Sure we will improve the documentation. Thank you for highlighting this issue.