private static string GenerateText(string text, bool replace, ITextVariables variables)
 {
     if (replace) {
         var replacer = new TextReplacer();
         return replacer.ReplaceVariables(text, variables);
     } else {
         return text;
     }
 }
        private XNode GenerateNode(XNode node, string environment, HashSet<string> allEnvironments, ITextVariables variables, bool replace)
        {
            var element = node as XElement;
            if (element != null) {
                if (IsElementForEnvironment(element, environment, allEnvironments)) {
                    if (IsVarElement(element)) {
                        SetVariable(element, replace, variables);
                        return null;
                    } else {
                        return BuildConfigForEnvironment(element, environment, allEnvironments, replace, variables);
                    }
                } else {
                    return null;
                }
            }

            var text = node as XText;
            if (text != null) {
                if (replace) {
                    var replacer = new TextReplacer();
                    return new XText(replacer.ReplaceVariables(text.Value, variables));
                } else {
                    return node;
                }
            }

            return node;
        }