本文整理匯總了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;
}
}