private CommandProcessorBase PrepareFromAst(ExecutionContext context, out string resolvedCommandName) { string str; FunctionDefinitionAst ast2; ExportVisitor astVisitor = new ExportVisitor(); Ast parent = this._commandAst; while (parent.Parent != null) { parent = parent.Parent; } parent.Visit(astVisitor); resolvedCommandName = this._commandAst.GetCommandName(); CommandProcessorBase base2 = null; int num = 0; while (astVisitor.DiscoveredAliases.TryGetValue(resolvedCommandName, out str)) { num++; if (num > 5) { break; } resolvedCommandName = str; } if (astVisitor.DiscoveredFunctions.TryGetValue(resolvedCommandName, out ast2)) { ScriptBlock scriptblock = ast2.IsWorkflow ? CreateFakeScriptBlockForWorkflow(ast2) : new ScriptBlock(ast2, ast2.IsFilter); base2 = CommandDiscovery.CreateCommandProcessorForScript(scriptblock, context, true, context.EngineSessionState); } return(base2); }
public static void LoadExportVisitors(string gameType = "Unreal", Assembly loadFrom = null) { if ((object)loadFrom == null) { loadFrom = Assembly.GetExecutingAssembly(); } Type baseType = typeof(IExportObject); foreach (Type item in from x in loadFrom.GetTypes() where baseType.IsAssignableFrom(x) && x.GetCustomAttribute <CategoryAttribute>()?.Category == gameType select x) { string text = item.GetCustomAttribute <DescriptionAttribute>()?.Description; if (string.IsNullOrWhiteSpace(text)) { throw new InvalidDataException(item.FullName + " has no DescriptionAttribute!"); } ExportVisitor exportVisitor = (from x in item.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public).Select(CreateExportDelegate) where x != null select x).FirstOrDefault(); ExportVisitors[text] = (exportVisitor ?? throw new NotImplementedException(item.FullName + " has no Export Delegate!")); } }
public void ExportTo(ExportVisitor visitor) { visitor.Visit(this, ActionExtensions.NoOp); }
private CommandProcessorBase PrepareFromAst(ExecutionContext context, out string resolvedCommandName) { // Analyze the Ast var exportVisitor = new ExportVisitor(forCompletion: true); Ast ast = _commandAst; while (ast.Parent != null) { ast = ast.Parent; } ast.Visit(exportVisitor); resolvedCommandName = _commandAst.GetCommandName(); CommandProcessorBase commandProcessor = null; string alias; int resolvedAliasCount = 0; while (exportVisitor.DiscoveredAliases.TryGetValue(resolvedCommandName, out alias)) { resolvedAliasCount += 1; if (resolvedAliasCount > 5) break; // give up, assume it's recursive resolvedCommandName = alias; } FunctionDefinitionAst functionDefinitionAst; if (exportVisitor.DiscoveredFunctions.TryGetValue(resolvedCommandName, out functionDefinitionAst)) { // We could use the IAstToScriptBlockConverter to get the actual script block, but that can be fairly expensive for workflows. // IAstToScriptBlockConverter is public, so we might consider converting non-workflows, but the interface isn't really designed // for Intellisense, so we can't really expect good performance, so instead we'll just fall back on the actual // parameters we see in the ast. var scriptBlock = functionDefinitionAst.IsWorkflow ? CreateFakeScriptBlockForWorkflow(functionDefinitionAst) : new ScriptBlock(functionDefinitionAst, functionDefinitionAst.IsFilter); commandProcessor = CommandDiscovery.CreateCommandProcessorForScript(scriptBlock, context, true, context.EngineSessionState); } return commandProcessor; }