本文整理汇总了C#中Microsoft.Cci.BlobBuilder.TryWriteBytes方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.TryWriteBytes方法的具体用法?C# BlobBuilder.TryWriteBytes怎么用?C# BlobBuilder.TryWriteBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Cci.BlobBuilder
的用法示例。
在下文中一共展示了BlobBuilder.TryWriteBytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteData
public void WriteData(BlobBuilder resourceWriter)
{
if (_fileReference == null)
{
try
{
using (Stream stream = _streamProvider())
{
if (stream == null)
{
throw new InvalidOperationException(CodeAnalysisResources.ResourceStreamProviderShouldReturnNonNullStream);
}
var count = (int)(stream.Length - stream.Position);
resourceWriter.WriteInt32(count);
int bytesWritten = resourceWriter.TryWriteBytes(stream, count);
if (bytesWritten != count)
{
throw new EndOfStreamException(
string.Format(CultureInfo.CurrentUICulture, CodeAnalysisResources.ResourceStreamEndedUnexpectedly, bytesWritten, count));
}
resourceWriter.Align(8);
}
}
catch (Exception e)
{
throw new ResourceException(_name, e);
}
}
}
示例2: 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));
}