Esempio n. 1
0
        private void PerformVariableReplacement(StringBuilder builder, string text)
        {
            var start  = 0;
            var length = text.Length;

            while (start < length)
            {
                var match = VariableRegex.Match(text, start);

                if (!match.Success)
                {
                    builder.Append(text, start, length - start);
                    return;
                }

                builder.Append(text, start, match.Index);
                builder.Append(GetVariableReplacement(match));

                start = match.Index + match.Length;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Replaces the variable names with repective values in the supplied string.
        /// </summary>
        /// <param name="input">The string which to have the evaluation applied.</param>
        /// <param name="hostVariables">The collection of variables to be queried.</param>
        /// <returns>String</returns>
        public static string EvaluateVariable(string input, Dictionary <string, string> hostVariables)
        {
            if (hostVariables != null && !string.IsNullOrWhiteSpace(input))
            {
                var match = VariableRegex.Match(input);

                if (match.Success)
                {
                    do
                    {
                        var key = match.Groups[1].Value;

                        if (hostVariables.ContainsKey(key))
                        {
                            input = input.Replace(match.Value, hostVariables[key]);
                        }
                    } while ((match = match.NextMatch()).Success);
                }
            }

            return(input);
        }