本文整理汇总了C#中IStream.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IStream.Write方法的具体用法?C# IStream.Write怎么用?C# IStream.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IStream
的用法示例。
在下文中一共展示了IStream.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
public void Write(IStream stream, object somethingToWrite, int level)
{
objectCounter.Add(somethingToWrite);
stream.Write(string.Format("#{0} : {1}.", objectCounter.Count, somethingToWrite.GetType().Name));
stream.WriteLine();
foreach (var propertyInfo in somethingToWrite.GetType().GetProperties(DomainGenerator.FlattenHierarchyBindingFlag))
{
level.Times(() => stream.Write(" "));
stream.Write(string.Format("{0} = ", propertyInfo.Name));
if (primitivesWriter.IsMatch(propertyInfo.PropertyType))
{
primitivesWriter.Write(stream, propertyInfo.PropertyType, propertyInfo.GetValue(somethingToWrite, null));
stream.WriteLine();
continue;
}
//try
//{
// var value = propertyInfo.GetValue(somethingToWrite, null);
// if (objectCounter.Contains(value))
// {
// stream.Write(string.Format("#{0} : {1}.", objectCounter.IndexOf(value) + 1, propertyInfo.PropertyType.Name));
// stream.WriteLine();
// continue;
// }
// Write(stream, value, ++level);
//}
//catch (Exception)
//{
// stream.Write(string.Format("#dunno : {0}.", propertyInfo.PropertyType.Name));
// stream.WriteLine();
// continue;
//}
}
}
示例2: MarshalInterface
public void MarshalInterface(IStream pstm, ref Guid riid, IntPtr pv, uint dwDestContext, IntPtr pvDestContext, uint MSHLFLAGS)
{
uint written;
byte[] data = ComUtils.CreateStandardMarshal(_binding);
pstm.Write(data, (uint)data.Length, out written);
}
示例3: ToIStream
public static unsafe IStream ToIStream(Stream stream,
ref IStream comStream)
{
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
uint num = 0;
IntPtr pcbWritten = new IntPtr((void*)&num);
comStream.Write(buffer, buffer.Length, pcbWritten);
return comStream;
}
示例4: Write
public void Write(IStream stream, int? intProperty)
{
var stringBuilder = new StringBuilder();
if (intProperty.HasValue)
stringBuilder.Append(intProperty.Value);
else
stringBuilder.Append("null");
stringBuilder.Append(" : Int32.");
stream.Write(stringBuilder.ToString());
}
示例5: CopyTo
public void CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
{
var bytes = new byte[cb];
int read = this.stream.Read(bytes, 0, (int)cb);
if (pcbRead != IntPtr.Zero)
{
Marshal.WriteInt64(pcbRead, read);
}
pstm.Write(bytes, (int)cb, pcbWritten);
}
示例6: Write
public void Write(IStream stream, Guid? property)
{
var stringBuilder = new StringBuilder();
if (property.HasValue)
stringBuilder.Append(property.Value.ToString());
else
stringBuilder.Append("null");
stringBuilder.Append(" : Guid.");
stream.Write(stringBuilder.ToString());
}
示例7: CopyTo
/// <inheritdoc/>
public void CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten) {
if (cb > int.MaxValue)
cb = int.MaxValue;
else if (cb < 0)
cb = 0;
int sizeToRead = (int)cb;
if (stream.Position + sizeToRead < sizeToRead || stream.Position + sizeToRead > stream.Length)
sizeToRead = (int)(stream.Length - Math.Min(stream.Position, stream.Length));
var buffer = new byte[sizeToRead];
Read(buffer, sizeToRead, pcbRead);
if (pcbRead != null)
Marshal.WriteInt64(pcbRead, Marshal.ReadInt32(pcbRead));
pstm.Write(buffer, buffer.Length, pcbWritten);
if (pcbWritten != null)
Marshal.WriteInt64(pcbWritten, Marshal.ReadInt32(pcbWritten));
}
示例8: CopyTo
public unsafe long CopyTo(IStream streamDest, long numberOfBytesToCopy, out long bytesWritten)
{
bytesWritten = 0L;
fixed (byte* numPtr = this.tempBuffer)
{
while (numberOfBytesToCopy > 0L)
{
int numberOfBytesToRead = this.sourceStream.Read(this.tempBuffer, 0, (int) Math.Min(numberOfBytesToCopy, (long) this.tempBuffer.Length));
if (numberOfBytesToRead != 0)
{
streamDest.Write((IntPtr) ((void*) numPtr), numberOfBytesToRead);
numberOfBytesToCopy -= (long) numberOfBytesToRead;
bytesWritten += (long) numberOfBytesToRead;
}
else
break;
}
}
return bytesWritten;
}
示例9: OutOfMemoryException
void IStream.CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
{
int num = 0x1000;
IntPtr buf = Marshal.AllocHGlobal(num);
if (buf == IntPtr.Zero)
{
throw new OutOfMemoryException();
}
long num2 = 0L;
try
{
while (num2 < cb)
{
int length = num;
if ((num2 + length) > cb)
{
length = (int)(cb - num2);
}
int len = this.Read(buf, length);
if (len == 0)
{
goto Label_006C;
}
if (pstm.Write(buf, len, pcbWritten) != len)
{
throw EFail("Wrote an incorrect number of bytes");
}
num2 += len;
}
}
finally
{
Marshal.FreeHGlobal(buf);
}
Label_006C:
if ((pcbRead != null) && (pcbRead.Length > 0))
{
pcbRead = new IntPtr(num2);
pcbWritten = new IntPtr(num2);
}
}
示例10: CopyTo
public void CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
{
byte[] buffer = new byte[CHUNK];
long written = 0;
int read = 0;
if (cb != 0)
{
SetSizeToPosition();
do
{
int count = CHUNK;
if (written + CHUNK > cb)
{
count = (int)(cb - written);
}
if ((read = _stream.Read(buffer, 0, count)) == 0)
{
break;
}
pstm.Write(buffer, read, IntPtr.Zero);
written += read;
} while (written < cb);
}
if (pcbRead != IntPtr.Zero)
{
Marshal.WriteInt64(pcbRead, written);
}
if (pcbWritten != IntPtr.Zero)
{
Marshal.WriteInt64(pcbWritten, written);
}
}
示例11: BuildHeader
protected override void BuildHeader(IStream propertyStream)
{
// 1.1.1 Set 8 bytes reserve.
propertyStream.WriteZero(8);
// 1.1.2 Set Next Recipient Id
Int32 recipientCount = RecipientProperties.Count;
propertyStream.Write(recipientCount);
// 1.1.3 Set Next Attachment Id
propertyStream.Write(AttachmentProperties.Count);
// 1.1.4 Set Recipient Count
propertyStream.Write(recipientCount);
// 1.1.5 Set Attachment Count
propertyStream.Write(AttachmentProperties.Count);
// 1.1.6 Set 8 bytes Reserve;
propertyStream.WriteZero(8);
}
示例12: CopyTo
public long CopyTo(IStream pstm, long cb, long[] pcbRead) {
int bufsize = 4096; // one page
IntPtr buffer = Marshal.AllocHGlobal(bufsize);
if (buffer == IntPtr.Zero) throw new OutOfMemoryException();
long written = 0;
try {
while (written < cb) {
int toRead = bufsize;
if (written + toRead > cb) toRead = (int) (cb - written);
int read = Read(buffer, toRead);
if (read == 0) break;
if (pstm.Write(buffer, read) != read) {
throw EFail("Wrote an incorrect number of bytes");
}
written += read;
}
}
finally {
Marshal.FreeHGlobal(buffer);
}
if (pcbRead != null && pcbRead.Length > 0) {
pcbRead[0] = written;
}
return written;
}
示例13: SaveUIState
/// <include file='doc\WindowPane.uex' path='docs/doc[@for="WindowPane.IVsUIElementPane.SaveUIElementState"]/*' />
/// <internalonly/>
/// <devdoc>
/// IVsUIElementPane implementation.
/// </devdoc>
int IVsUIElementPane.SaveUIElementState(IStream pstream)
{
Stream stateStream;
int hresult = SaveUIState(out stateStream);
if (ErrorHandler.Succeeded(hresult))
{
// Make sure the returned stream (if any) is properly disposed even if it's not readable or is empty
using (stateStream)
{
// If a stream was returned and is readable and have anything to read from it
if (stateStream != null && stateStream.CanRead && stateStream.Length > 0)
{
using (BinaryReader reader = new BinaryReader(stateStream))
{
byte[] bytes = new byte[stateStream.Length];
stateStream.Position = 0;
reader.Read(bytes, 0, bytes.Length);
uint written = 0;
pstream.Write(bytes, (uint)bytes.Length, out written);
pstream.Commit((uint)STGC.STGC_DEFAULT);
}
}
}
}
return hresult;
}
示例14: CopyTo
public void CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
{
byte[] buffer;
long written = 0;
int read;
int count;
if (cb != 0)
{
if (cb < 4096)
count = (int)cb;
else
count = 4096;
buffer = new byte[count];
SetSizeToPosition();
while (true)
{
if ((read = baseStream.Read(buffer, 0, count)) == 0)
break;
pstm.Write(buffer, read, IntPtr.Zero);
written += read;
if (written >= cb)
break;
if (cb - written < 4096)
count = (int)(cb - written);
}
}
if (pcbRead != IntPtr.Zero)
Marshal.WriteInt64(pcbRead, written);
if (pcbWritten != IntPtr.Zero)
Marshal.WriteInt64(pcbWritten, written);
}
示例15: CopyTo
/// <summary>
/// Copies a specified number of bytes from the current seek pointer in the stream
/// to the current seek pointer in another stream.
/// </summary>
/// <param name="pstm">
/// The destination stream. The pstm stream can be a new stream or a clone of the source stream.
/// </param>
/// <param name="cb">
/// The number of bytes to copy from the source stream.
/// </param>
/// <param name="pcbRead">
/// The actual number of bytes read from the source.
/// It can be set to IntPtr.Zero.
/// In this case, this method does not provide the actual number of bytes read.
/// </param>
/// <typeparam name="pcbRead">Native UInt64</typeparam>
/// <param name="pcbWritten">
/// The actual number of bytes written to the destination.
/// It can be set this to IntPtr.Zero.
/// In this case, this method does not provide the actual number of bytes written.
/// </param>
/// <typeparam name="pcbWritten">Native UInt64</typeparam>
/// <returns>
/// The actual number of bytes read (<paramref name="pcbRead"/>) and written (<paramref name="pcbWritten"/>) from the source.
/// </returns>
///<exception cref="ArgumentException">The sum of offset and count is larger than the buffer length.</exception>
///<exception cref="ArgumentNullException">buffer is a null reference.</exception>
///<exception cref="ArgumentOutOfRangeException">offset or count is negative.</exception>
///<exception cref="IOException">An I/O error occurs.</exception>
///<exception cref="NotSupportedException">The stream does not support reading.</exception>
///<exception cref="ObjectDisposedException">Methods were called after the stream was closed.</exception>
public void CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
{
if (TheStream != null)
{
byte[] sourceBytes = new byte[cb];
int currentBytesRead = 0;
long totalBytesRead = 0;
int currentBytesWritten = 0;
long totalBytesWritten = 0;
IntPtr bw = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)));
Marshal.WriteInt32(bw, 0);
while (totalBytesWritten < cb)
{
currentBytesRead = TheStream.Read(sourceBytes, 0, (int)(cb - totalBytesWritten));
// Has the end of the stream been reached?
if (currentBytesRead == 0) break;
totalBytesRead += currentBytesRead;
pstm.Write(sourceBytes, currentBytesRead, bw);
currentBytesWritten = Marshal.ReadInt32(bw);
if (currentBytesWritten != currentBytesRead)
{
Debug.WriteLine("ERROR!: The IStream Write is not writing all the bytes needed!");
}
totalBytesWritten += currentBytesWritten;
}
Marshal.FreeHGlobal(bw);
if (pcbRead != IntPtr.Zero) Marshal.WriteInt64(pcbRead, totalBytesRead);
if (pcbWritten != IntPtr.Zero) Marshal.WriteInt64(pcbWritten, totalBytesWritten);
}
else
{
TheIStream.CopyTo(pstm, cb, pcbRead, pcbWritten);
}
}