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


C# FileType.GetExistingCopyrightBanner方法代码示例

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


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

示例1: CheckFile

        static int CheckFile(string filename, CommandLineOptions options, FileType fileType)
        {
            var fileContents = File.ReadAllLines(filename);

            if (Enumerable.SequenceEqual(options.CopyrightBanner[fileType], fileContents.Take(options.CopyrightBanner[fileType].Length)))
            {
                // This file already has the correct copyright.
                return 0;
            }
            else
            {
                if (options.Validate)
                {
                    // Just report that the copyright does not match.
                    Console.WriteLine("Error: Wrong copyright: {0}", options.GetRelativeName(filename));
                }
                else
                {
                    // Find any existing copyright.
                    var existingCopyright = fileType.GetExistingCopyrightBanner(fileContents);

                    if (options.PreviousCopyrightBanner != null && !Enumerable.SequenceEqual(existingCopyright, options.PreviousCopyrightBanner[fileType]))
                    {
                        // Warn if what we tried to overwrite doesn't match the expected previous (then don't actually edit anything).
                        Console.WriteLine("Warning: Skipping {0}: doesn't match previous copyright", options.GetRelativeName(filename));
                    }
                    else
                    {
                        // Remove the old copyright.
                        var withoutOldCopyright = fileContents.Skip(existingCopyright.Count());

                        // Insert the new copyright.
                        var withNewCopyright = options.CopyrightBanner[fileType].Concat(withoutOldCopyright);

                        // Write out the new file.
                        Console.WriteLine("Warning: Updating copyright: {0}", options.GetRelativeName(filename));

                        File.WriteAllLines(filename, withNewCopyright);
                    }
                }

                return 1;
            }
        }
开发者ID:fengweijp,项目名称:Win2D,代码行数:44,代码来源:Program.cs


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