Reporting Engine - Conditional expression and System.Object type

Hello,

I found a problem in the use case where the model of the Report has a property of type ‘object’ (mainly because the property is dynamic and can contain different types) and where I use this property set with a Boolean value and with the template syntax for a conditional expression.

It seems that the Template engine is not able to detect that the property has a Boolean property.

Example with this model definition, where the “Value” property has the type “object” and where a Boolean value is assigned:

public class Model
{
    public object Value { get; set; }
}

bool booleanValue = true;
var reportData = new Model { Value = booleanValue };

With the following template syntax, it returns the type “Boolean”:

<<[Value.GetType()]>>

=> return System.Boolean

However, we it’s used as part of a if-then tag or a check tag, the conditional expression throws an error because the type is not Boolean:

<<if [Value == true]>>True<<else>>False<</if>>

=> Error! Can not apply operator ‘==’ to operands of type ‘System.Object’ and ‘System.Boolean’.

<<check [Value == true]>>

=> Error! Can not apply operator ‘==’ to operands of type ‘System.Object’ and ‘System.Boolean’.

For now, the only workaround I find is to use the string representation of the Boolean value but I don’t like:

<<check [Value.ToString() == "True"]>>

Is it a bug of the engine?
Is there any better way to use a property of type “object” in a conditional expression?

Thanks.

@nicolaspose

As per LINQ Reporting Engine Features, the engine supports a subset of C# language in its template expressions. In pure C#, it is impossible to apply == operator to operands of types Object and Boolean, which can be verified using a C# compiler. The engine behaves the same, so this is definitely not a bug but expected behavior. You may use any workaround for this scenario that better suits your needs as you would use in pure C#.

@ivan.lyagin

Thanks for your explanations. It makes sense to me now.
I will use workaround to faciliate the usage for end-user.

This topic can be closed.

1 Like