代码之家  ›  专栏  ›  技术社区  ›  Matthew Goulart

无法在Unity中查看Dictionary<int,Type>的linq扩展方法

  •  1
  • Matthew Goulart  · 技术社区  · 8 年前

    我有 Dictionary<int, Type> msgTypes 在类库中。净4.6。

    此DLL将导入到具有的unity项目中。NET框架设置为4。十、

    我试图调试DLL中的代码,所以我还将PDB导入unity,并使用unity工具将VS2017附加到unity进程。

    我有以下代码行:

    ...msgTypes.First(x => x.Value == typeof(TIn)).Key...
    

    这在unity中造成了错误,因为它说找不到匹配项。。。

    下面的图片是我走到那一行时看到的: debug watch

    在unity中linq的支持有问题吗?“不支持节点”是什么意思?我做错了什么?

    以下是整个方法,以防感兴趣:

    private Dictionary<int, Type> msgTypes = new Dictionary<int, Type>();
    
    public byte[] Prepare<TIn>(TIn message)
    {
        var content = msgSerializer.Serialize(message);
    
            byte[] payload = new byte[content.Length + LengthPrefixWidth + IdPrefixWidth];
    
            Buffer.BlockCopy(BitConverter.GetBytes((short)content.Length + IdPrefixWidth), 0, payload, 0, LengthPrefixWidth);
            Buffer.BlockCopy(BitConverter.GetBytes((short)msgTypes.First(x => x.Value == typeof(TIn)).Key), 0, payload, LengthPrefixWidth, IdPrefixWidth);
            Buffer.BlockCopy(content, 0, payload, LengthPrefixWidth + IdPrefixWidth, content.Length);
    
            return payload;
        }
    

    顺便说一句,这本字典是填充的,代码很长,所以我没有发布它,但是在那里 字典中的值,尤其是我要查找的值也存在。

    编辑

    我注意到 TIn 产生错误:

    标识符 不在范围之内

    编辑2

    如果我更改以下内容,则此代码有效:

    Buffer.BlockCopy(BitConverter.GetBytes((short)msgTypes.First(x => x.Value == typeof(TIn)).Key), 0, payload, LengthPrefixWidth, IdPrefixWidth);
    

    致:

    Buffer.BlockCopy(BitConverter.GetBytes((short)msgTypes.First(x => x.Value == typeof(StatisticsRequest)).Key), 0, payload, LengthPrefixWidth, IdPrefixWidth);
    

    这告诉我unity对泛型的处理有问题。此外,也没有办法“观看”通用的 ,根据VS,它并不存在。。。泛型有些可疑。。。

    0 回复  |  直到 8 年前