0%

c#在使用protobuf过程中遇到的小坑

写了 .proto 文件,编译成 c# 使用。在使用时,发现有一些特性一直没有补全。

比如文档说到了:

The collection type for repeated fields is always RepeatedField<T>. This type is like List<T> but with a few extra convenience methods, such as an Add overload accepting a collection of items, for use in colleciton initializers.

但是我定新建一个 repeated 字段后并没有它说到的 Add() 方法,然后在网上查到了别人的代码的的确确用了 Add 方法。

查了挺久,没发现有人和我有类似问题,最后发现只是因为没有安装 protobuf 的依赖。

由于.proto生成的c#代码也是依赖于 Google.Protobuf 的,所以在没有安装之前一直没有补全,安装之后就好了。

本文地址: https://www.chimaoshu.top/c-在使用protobuf过程中遇到的小坑/
版权声明:本博客所有文章除特别声明外,均采用 Apache License 2.0 许可协议,转载请注明出处。

Welcome to my other publishing channels