예제 #1
0
        /// <summary>
        /// Replace a variable in the <c>RouteTemplate</c> with a specified value.
        /// </summary>
        /// <param name="variableName">The variable name to replace.</param>
        /// <param name="variableValue">The value to replace with.</param>
        /// <param name="workingRoute">An 'in progress' route that may contain values that have already been replaced.</param>
        /// <returns>A <c>workingRoute</c></returns>
        public string SetVariable(string variableName, string variableValue, string workingRoute = null)
        {
            if (!variableName.StartsWith(VariableStartChar.ToString()) && !variableName.EndsWith(VariableEndChar.ToString()))
            {
                variableName = $"{VariableStartChar}{variableName}{VariableEndChar}";
            }

            return(!string.IsNullOrEmpty(workingRoute) ? workingRoute.Replace(variableName, variableValue) : RouteTemplate.Replace(variableName, variableValue));
        }
예제 #2
0
        private string RemoveVariableChars(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return(input);
            }

            input = input.Replace(VariableStartChar.ToString(), string.Empty)
                    .Replace(VariableEndChar.ToString(), string.Empty);
            return(input);
        }
예제 #3
0
        private string RemoteVariableChars(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return(input);
            }

            var result = new string(input.ToArray());

            result = result.Replace(VariableStartChar.ToString(), string.Empty).Replace(VariableEndChar.ToString(), string.Empty);
            return(result);
        }
예제 #4
0
        /// <summary>
        /// Replace a variable in the <c>RouteFormat</c> with a specified value.
        /// </summary>
        /// <param name="variableName">The variable name to replace.</param>
        /// <param name="variableValue">The value to replace with.</param>
        /// <param name="workingRoute">An 'in progress' route that may contain values that have already been replaced.</param>
        /// <returns>A <c>workingRoute</c></returns>
        public string SetVariable(string variableName, string variableValue, string workingRoute = null)
        {
            if (!variableName.StartsWith(VariableStartChar.ToString()) && !variableName.EndsWith(VariableEndChar.ToString()))
            {
                variableName = string.Format("{1}{0}{2}", variableName, VariableStartChar, VariableEndChar);
            }

            if (!string.IsNullOrEmpty(workingRoute))
            {
                return(workingRoute.Replace(variableName, variableValue));
            }
            else
            {
                return(RouteFormat.Replace(variableName, variableValue));
            }
        }