Is there a way to infer the resulting type of an Ast without evaluating it #21438
-
I would like to write an argument completer for a cmdlet which completes on the property names of an InputObject (like I figured I could use the CommandAst which is passed to the completer to find out what expressions precede the function in the pipeline but I can't seem to figure out how to then get the type that would result from this expression without evaluating it with System.Management.Automation/engine/parser/TypeInferenceVisitor.cs seems to be doing something like this and System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs has a Or is there maybe some other way to find out type information of pipeline input in argument completers? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I don't think you can do this without reflection, so you may as well use the Type Inference API rather than trying to reimplement it. Here's an example of how you can do it:
Alternatively if you want to stick with public APIs you could parse the whole script to get the script text, replace the command at your cursor with |
Beta Was this translation helpful? Give feedback.
I don't think you can do this without reflection, so you may as well use the Type Inference API rather than trying to reimplement it. Here's an example of how you can do it: