Exemple #1
0
        public static string HandleCommands(string str, KScriptContainer container, KScriptBaseObject parent, bool parse_immediately = false)
        {
            string temp_string = str;

            List <ICommand> commands = GetCommands(str, container, parent);

            if (commands.Count > 0)
            {
                foreach (ICommand item in commands)
                {
                    if (item.IsCommandObject)
                    {
                        if (parse_immediately)
                        {
                            temp_string = ReplaceFirst(temp_string, item.GetCommandObject().CommandParameters, item.GetCommandObject().CalculateValue());
                        }
                        else
                        {
                            string id = Guid.NewGuid().ToString();
                            temp_string = ReplaceFirst(temp_string, item.GetCommandObject().CommandParameters, $"[{id}]");
                            container.GetCommandStore().Add($"[{id}]", item.GetCommandObject());
                        }
                    }
                }

                if (!parse_immediately)
                {
                    return(ReturnCommandString(temp_string, container, parent));
                }
            }

            return(temp_string);
        }
Exemple #2
0
        public static string ReturnCommandString(string str, KScriptContainer container, KScriptBaseObject parent)
        {
            if (container.GetCommandStore().Any())
            {
                string temp_string = str;

                foreach (KeyValuePair <string, ICommandObject> item in container.GetCommandStore().ToList())
                {
                    string val = item.Value.GetCommandObject().CalculateValue();
                    temp_string = temp_string.Replace(item.Key, val);
                }

                container.GetCommandStore().Clear();
                return(temp_string);
            }

            return(str);
        }