本文整理汇总了C#中System.Byte.All方法的典型用法代码示例。如果您正苦于以下问题:C# Byte.All方法的具体用法?C# Byte.All怎么用?C# Byte.All使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Byte
的用法示例。
在下文中一共展示了Byte.All方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IdentifyCategory
/// <summary>
/// Given the first few bytes of content, decide what the FileCategory
/// should be, based on what's in the Content.<br/>
/// This should be called before deciding how to set the content.
/// </summary>
/// <param name="firstBytes">At least the first four bytes of the file read in binary form - can be longer if you wish</param>
/// <returns>The type that should be used to store this file.</returns>
public static FileCategory IdentifyCategory(byte[] firstBytes)
{
var firstFour = new Byte[4];
int atMostFour = Math.Min(4, firstBytes.Length);
Array.Copy(firstBytes, 0, firstFour, 0, atMostFour);
var returnCat = (atMostFour < 4) ? FileCategory.TOOSHORT : FileCategory.OTHER; // default if none of the conditions pass
if (firstFour.SequenceEqual(CompiledObject.MagicId))
{
returnCat = FileCategory.KSM;
}
else
{
bool isAscii = firstFour.All(b => b == (byte)'\n' || b == (byte)'\t' || b == (byte)'\r' || (b >= (byte)32 && b <= (byte)127));
if (isAscii)
returnCat = FileCategory.ASCII;
}
return returnCat;
// There is not currently an explicit test for KERBOSRIPT versus other types of ASCII.
// At current, any time you want to test for is Kerboscript, make sure to test for is ASCII too,
// since nothing causes a file to become type kerboscript yet.
}