static string DeclareLocalVariables(CalamariVariableDictionary variables) { var output = new StringBuilder(); foreach (var variableName in variables.GetNames().Where(name => !SpecialVariables.IsLibraryScriptModule(name))) { if (SpecialVariables.IsExcludedFromLocalVariables(variableName)) { continue; } // This is the way we used to fix up the identifiers - people might still rely on this behavior var legacyKey = new string(variableName.Where(char.IsLetterOrDigit).ToArray()); // This is the way we should have done it var smartKey = new string(variableName.Where(IsValidPowerShellIdentifierChar).ToArray()); if (legacyKey != smartKey) { WriteVariableAssignment(output, legacyKey, variableName); } WriteVariableAssignment(output, smartKey, variableName); } return(output.ToString()); }