本文整理汇总了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;
}
}