public static ListTag CreateFor(TemplateObject input) { return(input switch { ListTag ltag => ltag, IListTagForm lform => lform.ListForm, DynamicTag dtag => CreateFor(dtag.Internal), TextTag _ => For(input.ToString()), _ => new ListTag(new List <TemplateObject>() { input }), });
/// <summary>Returns a FunctionTag for the given text.</summary> /// <param name="data">The data.</param> /// <param name="input">The input text.</param> /// <returns>A TagTypeTag.</returns> public static FunctionTag For(TagData data, string input) { if (!input.Contains('|')) { CommandScript script = data.Engine.GetFunction(input); if (script == null) { throw data.Error($"Unknown script name '{TextStyle.Separate}{input}{TextStyle.Base}'."); } return(new FunctionTag(script)); } ListTag list = ListTag.For(input); if (list.Internal.Count < 2) { throw data.Error("Cannot construct FunctionTag with empty input."); } string type = list.Internal[0].ToString(); if (type == "anon") { if (list.Internal.Count < 4) { throw data.Error("Cannot construct FunctionTag without start line, name, and commandlist input."); } string name = list.Internal[1].ToString(); int startLine = (int)IntegerTag.For(list.Internal[2], data).Internal; string commands = list.Internal[3].ToString(); CommandScript script = ScriptParser.SeparateCommands(name, commands, data.Engine, startLine, data.DBMode); if (script == null) { throw data.Error("Anonymous function failed to generate."); } script.TypeName = CommandScript.TYPE_NAME_ANONYMOUS; script.IsAnonymous = true; script.AnonymousString = input["anon|".Length..];