当前位置: 首页>>代码示例>>C#>>正文


C# CodeCompileUnit.CompileToCSharpSourceCode方法代码示例

本文整理汇总了C#中System.CodeDom.CodeCompileUnit.CompileToCSharpSourceCode方法的典型用法代码示例。如果您正苦于以下问题:C# CodeCompileUnit.CompileToCSharpSourceCode方法的具体用法?C# CodeCompileUnit.CompileToCSharpSourceCode怎么用?C# CodeCompileUnit.CompileToCSharpSourceCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.CodeDom.CodeCompileUnit的用法示例。


在下文中一共展示了CodeCompileUnit.CompileToCSharpSourceCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteFileWithBackups

        /// <summary>
        /// Writes a file to disk and creates backup copies if a file with the same name already exists
        /// </summary>
        /// <remarks>Backups are numbered i.e. .1, .2, .3, .4, etc and rotate up as new copies are made (i.e. if .1 exists, it will be renamed .2 and the current one renamed to .1, etc)</remarks>
        private void WriteFileWithBackups(string path, CodeCompileUnit code)
        {
            if (File.Exists(path)) // existing version present; make backups as necessary
            {
                uint maxBackups = Parameters.MaxBackupCopies;

                uint i = maxBackups;
                do // find and move existing backups if needed
                {
                    string instanceFileName = path + "." + i.ToString(CultureInfo.InvariantCulture);
                    bool instanceExists = File.Exists(instanceFileName);

                    if (i == maxBackups && instanceExists) File.Delete(instanceFileName); // truncate a backup that's too old
                    if (i > 0 && i != maxBackups && instanceExists) File.Move(instanceFileName, string.Format("{0}.{1}", path, (i + 1).ToString(CultureInfo.InvariantCulture))); // move an existing backup up a number in the backups

                    i--;
                } while (i > 0);

                // move the pre-existing file into the file1.ext position
                File.Move(path, path + ".1");
            }

            // write new file
            File.WriteAllText(path, code.CompileToCSharpSourceCode());
        }
开发者ID:simonproctor,项目名称:Synthesis,代码行数:29,代码来源:Generator.cs


注:本文中的System.CodeDom.CodeCompileUnit.CompileToCSharpSourceCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。