Repository navigation
parser: throw ArgumentException when Evaluate cannot convert the result - #44
Merged
Merged
Conversation
After parsing, Evaluate converted the result to object or TResult with
Expression.Convert. When there was no such conversion, as for a call
of a void method or for Evaluate<string>("1"), Expression.Convert threw
InvalidOperationException, although Evaluate reports an invalid
expression with ArgumentException.
Throw ArgumentException with a message like the C# error CS0030, such
as "Cannot convert type 'System.Void' to 'System.Object'.", and mention
this case in the XML comments of the Evaluate overloads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After parsing,
Evaluateconverts the result of the expression toobjectorTResult. When there was no such conversion,Expression.ConvertthrewInvalidOperationException, althoughEvaluatereports an invalid expression withArgumentException. This happened in all overloads for a call of avoidmethod, such asEvaluate("TimeZoneInfo.ClearCachedData()"), and for a result without a conversion toTResult, such asEvaluate<string>("1").This PR throws
ArgumentExceptionwith a message like the C# error CS0030, for exampleCannot convert type 'System.Void' to 'System.Object'.The XML comments of theEvaluateoverloads now mention this case.Existing conversions are not affected:
Evaluate<int>("1.9")still returns1, andEvaluate<string>("1 :> object")still throwsInvalidCastExceptionwhen the value cannot be cast.