Repository navigation
parser: use TContext for the context parameter in Evaluate - #28
Merged
Merged
Conversation
Evaluate<TContext, TResult> created the context parameter with the
runtime type of the context but compiled a delegate that takes
TContext. When the context was an instance of a derived or
implementing type, such as Evaluate<IFace, object>("Value", impl), it
failed with "ParameterExpression of type 'Impl' cannot be used for
delegate parameter of type 'IFace'".
Create the parameter with TContext, so the expression can access the
members of TContext. Members declared only in the runtime type of the
context are not available, as for a variable of type TContext in C#.
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.
Evaluate<TContext, TResult>created the context parameter with the runtime type of the context but compiled a delegate that takesTContext. When the context was an instance of a derived or implementing type, such asEvaluate<IFace, object>("Value", impl), it failed withParameterExpression of type 'Impl' cannot be used for delegate parameter of type 'IFace'.This PR creates the parameter with
TContext, so the expression can access the members ofTContext. Members declared only in the runtime type of the context are not available, as for a variable of typeTContextin C#. Virtual members are still dispatched on the runtime type, soEvaluate<object, string>("ToString()", context)calls the override.Calls where the runtime type of the context is
TContextare not affected. The non-genericEvaluate(source, context)still binds the members of the runtime type.