Inheritance: System.IO.StringWriter
        public static XmlProgramRenamerResult RenameProgram(
            string programCode, string newProgramName)
        {
            try
            {
                var document = XDocument.Load(new StringReader(programCode));
                document.Declaration = new XDeclaration("1.0", "UTF-8", "yes");

                var program = document.Element("program");
                var header = program.Element("header");
                var programName = header.Element("programName");
                programName.SetValue(newProgramName);

                var writer = new XmlStringWriter();
                document.Save(writer, SaveOptions.None);
                var newProgramCode = writer.ToString();

                return new XmlProgramRenamerResult
                {
                    Status = XmlRenameStatus.Success,
                    NewProgramCode = newProgramCode
                };
            }
            catch (Exception)
            {
                return new XmlProgramRenamerResult
                {
                    Status = XmlRenameStatus.Error,
                    NewProgramCode = null
                };
            }
        }
        public static async Task<VersionConverterResult> ConvertToXmlVersion(
            string projectCode, string targetVersion)
        {
            // TODO XML: move to IDE.Core
            VersionConverterStatus error;
            var xml = "";

            if (!string.IsNullOrEmpty(projectCode))
            {
                //string projectCode;

                //using (var storage = StorageSystem.GetStorage())
                //{
                //    projectCode = await storage.ReadTextFileAsync(projectCodePath);
                //}

                if (projectCode != null)
                {
                    var document = XDocument.Load(new StringReader(projectCode));
                    document.Declaration = new XDeclaration("1.0", "UTF-8", "yes");

                    var inputVersion = GetInputVersion(document);

                    if (XmlConstants.SupportedXMLVersions.Contains(inputVersion))
                    {
                        return new VersionConverterResult
                        {
                            Error = VersionConverterStatus.NoError,
                            Xml = projectCode
                        };
                    }

                    if (double.Parse(inputVersion) < XmlConstants.MinimumCodeVersion)
                    {
                        return new VersionConverterResult
                        {
                            Error = VersionConverterStatus.VersionTooOld,
                            Xml = null
                        };
                    }

                    error = ConvertVersions(inputVersion, targetVersion, document);

                    if (error == VersionConverterStatus.NoError)
                    {
                        var writer = new XmlStringWriter();
                        document.Save(writer, SaveOptions.None);
                        xml = writer.GetStringBuilder().ToString();


                        //if (overwriteProject)
                        //{
                        //    using (var storage = StorageSystem.GetStorage())
                        //    {
                        //        try
                        //        {
                        //            await storage.WriteTextFileAsync(projectCodePath, xml);
                        //        }
                        //        catch
                        //        {
                        //            error = VersionConverterStatus.ProgramDamaged;
                        //        }
                        //    }
                        //}
                    }
                    else
                    {
                        error = VersionConverterStatus.ProgramDamaged;
                    }
                }
                else
                {
                    error = VersionConverterStatus.ProgramDamaged;
                }
            }
            else
            {
                error = VersionConverterStatus.ProgramDamaged;
            }

            return new VersionConverterResult { Xml = xml, Error = error };
        }
        //public async Task Save(string path = null)
        //{
        //    // TODO XML: move to IDE.Core

        //    if (path == null)
        //    {
        //        path = BasePath + "/" + StorageConstants.ProgramCodePath;
        //    }

        //    if (Debugger.IsAttached)
        //    {
        //        await SaveInternal(path);
        //    }
        //    else
        //    {
        //        try
        //        {
        //            await SaveInternal(path);
        //        }
        //        catch (Exception ex)
        //        {
        //            throw new Exception("Cannot write Project", ex);
        //        }
        //    }
        //}

        //private async Task SaveInternal(string path)
        //{
        //    // TODO XML: move to IDE.Core

        //    using (var storage = StorageSystem.GetStorage())
        //    {
        //        var writer = new XmlStringWriter();
        //        var document = CreateXml();
        //        document.Save(writer, SaveOptions.None);

        //        var xml = writer.GetStringBuilder().ToString();
        //        await storage.WriteTextFileAsync(path, xml);
        //    }
        //}


        public string ToXmlString()
        {
            var writer = new XmlStringWriter();
            var document = CreateXml();
            document.Save(writer, SaveOptions.None);
            return writer.ToString();
        }