本文整理汇总了C#中IBinaryReader.CanRead方法的典型用法代码示例。如果您正苦于以下问题:C# IBinaryReader.CanRead方法的具体用法?C# IBinaryReader.CanRead怎么用?C# IBinaryReader.CanRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBinaryReader
的用法示例。
在下文中一共展示了IBinaryReader.CanRead方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadString
/// <summary>
/// Reads a string
/// </summary>
/// <param name="reader">Reader</param>
/// <param name="offset">Offset of string</param>
/// <returns>The string or <c>null</c> if we could not read it</returns>
static string ReadString(IBinaryReader reader, uint offset) {
reader.Position = offset;
if (!reader.CanRead(2))
return null;
int size = reader.ReadUInt16();
int sizeInBytes = size * 2;
if (!reader.CanRead(sizeInBytes))
return null;
var stringData = reader.ReadBytes(sizeInBytes);
try {
return Encoding.Unicode.GetString(stringData);
}
catch {
return null;
}
}
示例2: CouldBeResourcesFile
/// <summary>
/// Returns true if it's possibly resources file data
/// </summary>
/// <param name="reader">Reader</param>
/// <returns></returns>
public static bool CouldBeResourcesFile(IBinaryReader reader) {
return reader.CanRead(4) && reader.ReadUInt32() == 0xBEEFCACE;
}
示例3: Initialize
/// <summary>
/// Reads the directory header and initializes <see cref="ResourceDirectory.directories"/> and
/// <see cref="ResourceDirectory.data"/>.
/// </summary>
/// <param name="reader"></param>
void Initialize(IBinaryReader reader) {
if (depth > MAX_DIR_DEPTH || !reader.CanRead(16)) {
InitializeDefault();
return;
}
characteristics = reader.ReadUInt32();
timeDateStamp = reader.ReadUInt32();
majorVersion = reader.ReadUInt16();
minorVersion = reader.ReadUInt16();
ushort numNamed = reader.ReadUInt16();
ushort numIds = reader.ReadUInt16();
int total = numNamed + numIds;
if (!reader.CanRead(total * 8)) {
InitializeDefault();
return;
}
dataInfos = new List<EntryInfo>();
dirInfos = new List<EntryInfo>();
long offset = reader.Position;
for (int i = 0; i < total; i++, offset += 8) {
reader.Position = offset;
uint nameOrId = reader.ReadUInt32();
uint dataOrDirectory = reader.ReadUInt32();
ResourceName name;
if ((nameOrId & 0x80000000) != 0)
name = new ResourceName(ReadString(reader, nameOrId & 0x7FFFFFFF) ?? string.Empty);
else
name = new ResourceName((int)nameOrId);
if ((dataOrDirectory & 0x80000000) == 0)
dataInfos.Add(new EntryInfo(name, dataOrDirectory));
else
dirInfos.Add(new EntryInfo(name, dataOrDirectory & 0x7FFFFFFF));
}
directories = new LazyList<ResourceDirectory>(dirInfos.Count, null, (ctx, i) => ReadResourceDirectory((int)i));
data = new LazyList<ResourceData>(dataInfos.Count, null, (ctx, i) => ReadResourceData((int)i));
}