小编Mil*_*vić的帖子

阅读与线BinaryReader在行

我使用下面的代码序列化的数据,从数据表。

var rows = new List<Dictionary<string, object[]>>();
Run Code Online (Sandbox Code Playgroud)

我从数据表中填写的行并将它们放在字典。不要问为什么:)

using(var fileStream = new FileStream(@"D:\temp.bin", FileMode.Create, FileAccess.Write, FileShare.None))
using(var bw = new BinaryWriter(fileStream))
{
    foreach(Dictionary<string, object[]> row in rows)
    {
        byte[] bytes = ObjectToByteArray(row);
        bw.Write(bytes);
    }
}
Run Code Online (Sandbox Code Playgroud)

随着下面的方法:

private static byte[] ObjectToByteArray(Dictionary<string, object[]> rows)
{
    var bf = new BinaryFormatter();
    using(var ms = new MemoryStream())
    {
        bf.Serialize(ms, rows);
        return ms.ToArray();
    }
}
Run Code Online (Sandbox Code Playgroud)

我试图做的是逐行反序列化,如果使用BinaryReader可以的话。问题是,我坚持只读取第一行。

我想实现的是:

using(BinaryReader reader = new BinaryReader(File.Open(@"D:\temp.bin", FileMode.Open)))
{
    int pos = 0;
    int length = (int)reader.BaseStream.Length;
    while(pos < length) …
Run Code Online (Sandbox Code Playgroud)

.net c# binaryreader

3
推荐指数
1
解决办法
3142
查看次数

是否可以通过COM互操作转发代表?

我有一节课:

public class A
{
public delegate void SetTextDel(string value);
public void Test()
{
      SetTextDel setText = someInterface.SetText;
      icom.Set(setText);
}
}

[ComVisible(true), Guid("81C99F84-AA95-41A5-868E-62FAC8FAC263"),   InterfaceType(ComInterfaceType.InterfaceIsDual)]
    public interface Icom
    {
        void Set(Delegate del);
    }

[ComVisible(true)]
    [Guid("6DF6B926-8EB1-4333-827F-DD814B868097")]
    [ClassInterface(ClassInterfaceType.None)]
    [ComDefaultInterface(typeof(Icom))]
    public class B : Icom
    {
         Set(Delegate del)
         {
              del.DynamicInvoke("some text");
         }
    }
Run Code Online (Sandbox Code Playgroud)

我在Set(Delegate del)中获得了targetinvocation异常.有没有更好的方法来转发委托作为参数?或者我在这里犯了一些我没有看到的错误.我想做的是将someInterface.SetText这个方法作为参数传递.谢谢你的帮助.

.net c# com com-interop visual-studio-2012

2
推荐指数
1
解决办法
734
查看次数

标签 统计

.net ×2

c# ×2

binaryreader ×1

com ×1

com-interop ×1

visual-studio-2012 ×1