Operators "And" and "Or" for types other than Boolean

Oct 22, 2010 at 10:21 PM
Edited Oct 22, 2010 at 10:21 PM

Hello. I've created an application based on Flee and I really like this library, but there is one exception.

Example source code:

ExpressionContext context = new ExpressionContext();
context.Imports.AddType(typeof(Math));

//"m" means decimal
context.Variables["a"] = 10m;
context.Variables["b"] = 20m;

IDynamicExpression eDynamic = context.CompileDynamic("a && b");

bool result = (bool)eDynamic.Evaluate();



I get an exception "AndOrElement: Operation 'And' is not defined for types 'Decimal' and 'Decimal'".
How can I fix it?

 


I've tried to modify source code of Flee, but I'm new to Visual Basic. I found a place where the exception is thrown, but I couldn't make it work.
I changed the method GetResultType in AndOr.vb file to:

	Protected Overrides Function GetResultType(ByVal leftType As System.Type, ByVal rightType As System.Type) As System.Type
Dim bitwiseOpType As Type = Utility.GetBitwiseOpType(leftType, rightType)
If Not bitwiseOpType Is Nothing Then
Return bitwiseOpType
ElseIf Me.AreBothChildrenOfType(GetType(Boolean)) Then
Return GetType(Boolean)
Else
Return GetType(Boolean)
End If
End Function


but then I get an exception in Evaluate method in Expression.vb file:

System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Source="Ciloci.Flee"
StackTrace:
at Flee Expression(Object , ExpressionContext , VariableCollection )
at Ciloci.Flee.Expression`1.Evaluate() in D:\Dokumenty\Piotrek\Ikosoft\Flee\src\Lib\InternalTypes\Expression.vb:line 154
at ConsoleTester.Module1.Main() in D:\Dokumenty\Piotrek\Ikosoft\Flee\src\ConsoleTester\Module1.vb:line 23
InnerException:

 

It seems that  MyLeftChild and MyRightChild should be converted to Boolean, but how?

Please help. Thank you for any working solutions ASAP.

 

Hello. I've created an application based on Flee and really like this library, but there is one exception.

Example source code:


ExpressionContext context = new ExpressionContext();
context.Imports.AddType(typeof(Math));

//"m" means decimal
context.Variables["a"] = 10m;
context.Variables["b"] = 20m;

IDynamicExpression eDynamic = context.CompileDynamic("a && b");

bool result = (bool)eDynamic.Evaluate();



I get an exception "AndOrElement: Operation 'And' is not defined for types 'Decimal' and 'Decimal'".
How can I fix it?
I've tried to modify source code of Flee, but I'm new to Visual Basic. I found a place where the exception is thrown, but I couldn't make it work.
I changed the method GetResultType in AndOr.vb file to:


	Protected Overrides Function GetResultType(ByVal leftType As System.Type, ByVal rightType As System.Type) As System.Type
Dim bitwiseOpType As Type = Utility.GetBitwiseOpType(leftType, rightType)
If Not bitwiseOpType Is Nothing Then
Return bitwiseOpType
ElseIf Me.AreBothChildrenOfType(GetType(Boolean)) Then
Return GetType(Boolean)
Else
Return GetType(Boolean)
End If
End Function




but then I get an exception in Evaluate method in Expression.vb file: