"If" for collections

0
lukacs.akos posted this 16 August 2022

Hi, My data source is a regular dotnet object, is it correct that the "If" must evaluate to True or False, and any other value leads to an error? If I have a collection, that may be empty, and I want to conditionally show some content if there are elements in that collection, than I should add a boolean property to my data model? There is no shortcut to for collections to treat it as False if the collection is null or empty, and treat it as True if the collection has elements?

10 Posts
10 Points
3 Comments
Order By: Standard | Newest | Votes
0
jles posted this 16 August 2022

Hi Lukas,

Yes, you are correct. There is no shortcut currently for .NET Object/C# kind of data sources. This is because Binding Paths can only be simple member selections (Member1.Member2...), and no arithmetic or other expressions are available. This will change with the next major release (v7.0), which is due in 2023 Q1. Version 7 will allow you to write full C# expressions and even statements as Binding Paths.

So yes, the only way to implement your wanted behavior is, like you already found out yourself, is by adding additional boolean property (e.g., "IsEmpty") to the collection type. You should also make sure your collection won't be null at runtime.

Just in case you didn't know, if you worked with XML based data sources instead, you would have the full power of XPath at your disposal. XML based data sources allow you much more than .NET Object based data sources currently do.

I hope this helps.

Best regards, Jure

155 Posts
295 Points
0
lukacs.akos posted this 17 August 2022

Thanks!

Could you elaborate on "Just in case you didn't know, if you worked with XML based data sources instead, you would have the full power of XPath at your disposal. XML based data sources allow you much more than .NET Object based data sources currently do."? Didn't look deeply into XML data source or XPath, because XPath is not something an end user authoring the template could do. Or maybe I'm wrong?

10 Posts
10 Points
0
jles posted this 19 August 2022

Hi Lucas,

To understand what XML based data sources offer, please read the following article: https://www.docentric.com/blog/2016/01/28/choosing-the-right-kind-of-a-data-source

Let me know if the article helped.

Regards, Jure

155 Posts
295 Points

Our 229035 members have posted 345 times in 102 discussions