/// <summary> /// Outputs the method signature with all arguments and a object selection argument if applicable /// </summary> /// <returns></returns> public string OutputMethodSignature(bool onlyRequiredArgs, bool withSelection) { // if we are not outputing withSelection and have only required args and return a // scalar, skip it otherwise we'll have duplicate method if (!withSelection && IsScalar && Args.All(a => a.Required)) { return(null); } var typeName = !withSelection ? DotNetTypeSingle : "TReturn"; var sb = new StringBuilder(" "); sb.Append(IsScalar ? $"{DotNetType} " : IsArray ? $"List<{typeName}> " : $"{typeName} "); sb.Append(DotNetName).Append(IsScalar || !withSelection ? "(" : $"<{typeName}>("); var argsOut = ArgsOutput(onlyRequiredArgs); sb.Append(argsOut); if (withSelection && !IsScalar) { if (argsOut.Length > 0) { sb.Append(", "); } sb.Append($"Expression<Func<{DotNetTypeSingle}, TReturn>> selection"); } sb.Insert(0, BuildCommentDoc(withSelection)); sb.AppendLine($");"); return(sb.ToString()); }
public bool NeedsLocalsDictionary() { if (!(Target is NameExpression nameExpr)) { return(false); } if (nameExpr.Name == "eval" || nameExpr.Name == "exec") { return(true); } if (nameExpr.Name == "dir" || nameExpr.Name == "vars" || nameExpr.Name == "locals") { // could be splatting empty list or dict resulting in 0-param call which needs context return(Args.All(arg => arg.Name == "*") && Kwargs.All(arg => arg.Name == "**")); } return(false); }