本文整理汇总了C#中BlobBuilder.WriteUTF16方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.WriteUTF16方法的具体用法?C# BlobBuilder.WriteUTF16怎么用?C# BlobBuilder.WriteUTF16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlobBuilder
的用法示例。
在下文中一共展示了BlobBuilder.WriteUTF16方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteDirectory
private void WriteDirectory(Directory directory, BlobBuilder writer, uint offset, uint level, uint sizeOfDirectoryTree, int virtualAddressBase, BlobBuilder dataWriter)
{
writer.WriteUInt32(0); // Characteristics
writer.WriteUInt32(0); // Timestamp
writer.WriteUInt32(0); // Version
writer.WriteUInt16(directory.NumberOfNamedEntries);
writer.WriteUInt16(directory.NumberOfIdEntries);
uint n = (uint)directory.Entries.Count;
uint k = offset + 16 + n * 8;
for (int i = 0; i < n; i++)
{
int id;
string name;
uint nameOffset = (uint)dataWriter.Position + sizeOfDirectoryTree;
uint directoryOffset = k;
Directory subDir = directory.Entries[i] as Directory;
if (subDir != null)
{
id = subDir.ID;
name = subDir.Name;
if (level == 0)
{
k += SizeOfDirectory(subDir);
}
else
{
k += 16 + 8 * (uint)subDir.Entries.Count;
}
}
else
{
//EDMAURER write out an IMAGE_RESOURCE_DATA_ENTRY followed
//immediately by the data that it refers to. This results
//in a layout different than that produced by pulling the resources
//from an OBJ. In that case all of the data bits of a resource are
//contiguous in .rsrc$02. After processing these will end up at
//the end of .rsrc following all of the directory
//info and IMAGE_RESOURCE_DATA_ENTRYs
IWin32Resource r = (IWin32Resource)directory.Entries[i];
id = level == 0 ? r.TypeId : level == 1 ? r.Id : (int)r.LanguageId;
name = level == 0 ? r.TypeName : level == 1 ? r.Name : null;
dataWriter.WriteUInt32((uint)(virtualAddressBase + sizeOfDirectoryTree + 16 + dataWriter.Position));
byte[] data = new List<byte>(r.Data).ToArray();
dataWriter.WriteUInt32((uint)data.Length);
dataWriter.WriteUInt32(r.CodePage);
dataWriter.WriteUInt32(0);
dataWriter.WriteBytes(data);
while ((dataWriter.Count % 4) != 0)
{
dataWriter.WriteByte(0);
}
}
if (id >= 0)
{
writer.WriteInt32(id);
}
else
{
if (name == null)
{
name = string.Empty;
}
writer.WriteUInt32(nameOffset | 0x80000000);
dataWriter.WriteUInt16((ushort)name.Length);
dataWriter.WriteUTF16(name);
}
if (subDir != null)
{
writer.WriteUInt32(directoryOffset | 0x80000000);
}
else
{
writer.WriteUInt32(nameOffset);
}
}
k = offset + 16 + n * 8;
for (int i = 0; i < n; i++)
{
Directory subDir = directory.Entries[i] as Directory;
if (subDir != null)
{
this.WriteDirectory(subDir, writer, k, level + 1, sizeOfDirectoryTree, virtualAddressBase, dataWriter);
if (level == 0)
{
k += SizeOfDirectory(subDir);
}
else
{
k += 16 + 8 * (uint)subDir.Entries.Count;
}
}
}
}
示例2: WriteUTF16
public void WriteUTF16()
{
var writer = new BlobBuilder(4);
writer.WriteUTF16("");
writer.WriteUTF16("a");
writer.WriteUTF16("");
writer.WriteUTF16(new char[0]);
writer.WriteUTF16(new char[] { '\ud800' }); // hi surrogate
writer.WriteUTF16("\udc00"); // lo surrogate
writer.WriteUTF16("\ud800\udc00"); // pair
writer.WriteUTF16(new char[] { '\udc00', '\ud800' }); // lo + hi
writer.WriteUTF16("\u1234");
AssertEx.Equal(new byte[]
{
0x61, 0x00,
0x00, 0xD8,
0x00, 0xDC,
0x00, 0xD8, 0x00, 0xDC,
0x00, 0xDC, 0x00, 0xD8,
0x34, 0x12
}, writer.ToArray());
}
示例3: Link
public void Link()
{
var builder1 = new BlobBuilder(16);
builder1.WriteByte(1);
var builder2 = new BlobBuilder(16);
builder2.WriteByte(2);
var builder3 = new BlobBuilder(16);
builder3.WriteByte(3);
var builder4 = new BlobBuilder(16);
builder4.WriteByte(4);
var builder5 = new BlobBuilder(16);
builder5.WriteByte(5);
builder2.LinkPrefix(builder1);
AssertEx.Equal(new byte[] { 1, 2 }, builder2.ToArray());
Assert.Throws<InvalidOperationException>(() => builder1.ToArray());
Assert.Throws<InvalidOperationException>(() => builder2.LinkPrefix(builder1));
Assert.Throws<InvalidOperationException>(() => builder1.WriteByte(0xff));
Assert.Throws<InvalidOperationException>(() => builder1.WriteBytes(1, 10));
Assert.Throws<InvalidOperationException>(() => builder1.WriteBytes(new byte[] { 1 }));
Assert.Throws<InvalidOperationException>(() => builder1.ReserveBytes(1));
Assert.Throws<InvalidOperationException>(() => builder1.GetBlobs());
Assert.Throws<InvalidOperationException>(() => builder1.ContentEquals(builder1));
Assert.Throws<InvalidOperationException>(() => builder1.WriteUTF16("str"));
Assert.Throws<InvalidOperationException>(() => builder1.WriteUTF8("str", allowUnpairedSurrogates: false));
builder2.LinkSuffix(builder3);
AssertEx.Equal(new byte[] { 1, 2, 3 }, builder2.ToArray());
Assert.Throws<InvalidOperationException>(() => builder3.LinkPrefix(builder5));
builder2.LinkPrefix(builder4);
AssertEx.Equal(new byte[] { 4, 1, 2, 3 }, builder2.ToArray());
Assert.Throws<InvalidOperationException>(() => builder4.LinkPrefix(builder5));
builder2.LinkSuffix(builder5);
AssertEx.Equal(new byte[] { 4, 1, 2, 3, 5 }, builder2.ToArray());
}
示例4: Write_Errors
public unsafe void Write_Errors()
{
var builder = new BlobBuilder(16);
Assert.Throws<ArgumentNullException>(() => builder.WriteUTF16((char[])null));
Assert.Throws<ArgumentNullException>(() => builder.WriteUTF16((string)null));
Assert.Throws<ArgumentNullException>(() => builder.WriteUTF8(null, allowUnpairedSurrogates: true));
Assert.Throws<ArgumentNullException>(() => builder.WriteUTF8(null, allowUnpairedSurrogates: true));
Assert.Throws<ArgumentNullException>(() => builder.TryWriteBytes((Stream)null, 0));
Assert.Throws<ArgumentNullException>(() => builder.WriteBytes(null));
Assert.Throws<ArgumentNullException>(() => builder.WriteBytes(null, 0, 0));
Assert.Throws<ArgumentNullException>(() => builder.WriteBytes((byte*)null, 0));
Assert.Throws<ArgumentNullException>(() => builder.WriteBytes(default(ImmutableArray<byte>)));
Assert.Throws<ArgumentNullException>(() => builder.WriteBytes(default(ImmutableArray<byte>), 0, 0));
var bw = default(BlobWriter);
Assert.Throws<ArgumentNullException>(() => builder.WriteContentTo(ref bw));
Assert.Throws<ArgumentNullException>(() => builder.WriteContentTo((Stream)null));
Assert.Throws<ArgumentNullException>(() => builder.WriteContentTo((BlobBuilder)null));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.TryWriteBytes(new MemoryStream(), -1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(0, -1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(new byte[] { }, 1, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(new byte[] { }, 0, 1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(new byte[] { }, 0, -1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(ImmutableArray<byte>.Empty, 1, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(ImmutableArray<byte>.Empty, 0, 1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(ImmutableArray<byte>.Empty, 1, -1));
}
示例5: WriteConstant
internal static void WriteConstant(BlobBuilder writer, object value)
{
if (value == null)
{
// The encoding of Type for the nullref value for FieldInit is ELEMENT_TYPE_CLASS with a Value of a 32-bit.
writer.WriteUInt32(0);
return;
}
var type = value.GetType();
if (type.GetTypeInfo().IsEnum)
{
type = Enum.GetUnderlyingType(type);
}
if (type == typeof(bool))
{
writer.WriteBoolean((bool)value);
}
else if (type == typeof(int))
{
writer.WriteInt32((int)value);
}
else if (type == typeof(string))
{
writer.WriteUTF16((string)value);
}
else if (type == typeof(byte))
{
writer.WriteByte((byte)value);
}
else if (type == typeof(char))
{
writer.WriteUInt16((char)value);
}
else if (type == typeof(double))
{
writer.WriteDouble((double)value);
}
else if (type == typeof(short))
{
writer.WriteInt16((short)value);
}
else if (type == typeof(long))
{
writer.WriteInt64((long)value);
}
else if (type == typeof(sbyte))
{
writer.WriteSByte((sbyte)value);
}
else if (type == typeof(float))
{
writer.WriteSingle((float)value);
}
else if (type == typeof(ushort))
{
writer.WriteUInt16((ushort)value);
}
else if (type == typeof(uint))
{
writer.WriteUInt32((uint)value);
}
else if (type == typeof(ulong))
{
writer.WriteUInt64((ulong)value);
}
else
{
// TODO: message
throw new ArgumentException();
}
}