Implicit conversion to string and other types...

Mar 18, 2011 at 7:49 AM


I am using the following code snippet to check if the expression results in desired result type:

        public bool IsValidateExpression(string sExpression, Type desiredResultType)
                m_context.Options.ResultType = desiredResultType;
                IDynamicExpression es = m_context.CompileDynamic(sExpression);
		return true;
            catch (ExpressionCompileException ex)
		return false;

The expressions that I am specifying typically result in a numeric value, and it should be possible to convert it to String. Unfortunately, if I specify the desired result type to be String, I get ExpressionCompilationError with the following message:

"RootExpressionElement: Cannot convert type 'Single' to expression result of 'String'"

Is there anyway I can avoid this? or is there a better way of checking if the specified expression will result in a value that could be assigned to an object of specified type?


Warm Regards,

- Vikram Lele