public static string FormatText(this object target, string format, CustomExpressionParse customExpressionParser, Func <string, string, string, object> argumentsCallback) { var tmp = TokenizeString(format); for (int i = 0; i < tmp.Length; i++) { if (tmp[i] is FormatElement fmt) { bool keep = customExpressionParser(fmt.Content.ToString(), out var newContent); if (!keep) { string pref = ""; switch (fmt.CodeType) { case CodeType.Block: pref = "$"; break; case CodeType.RecursiveExpression: pref = "£"; break; case CodeType.RecursiveBlock: pref = "$£"; break; } tmp[i] = new StringElement { Length = fmt.Length, Start = fmt.Start }; tmp[i].Content.Append($"{pref}[{fmt.Content}]"); } else { fmt.Content.Clear(); fmt.Content.Append(newContent); } } } using (var context = CreateScriptingSession(target)) { return(string.Concat(from t in tmp select Stringify(t, context, argumentsCallback))); } }
public static string FormatText(this IDisposable scriptingContext, string format, CustomExpressionParse customExpressionParser) { return(FormatText(scriptingContext, format, customExpressionParser, null)); }
public static string FormatText(this object target, string format, CustomExpressionParse customExpressionParser) { return(FormatText(target, format, customExpressionParser, null)); }