問題描述
如何為 C# 定義傳遞experimental_allow_proto3_optional 以在proto3 中啟用可選? (How to pass experimental_allow_proto3_optional for C# definitions to enable optional in proto3?)
我到處找這個。C# grpc 的人不知道怎麼做,並指向 grpc/grpc 的人提供工具,但你不能在那裡提問。我想我可以將其表述為一項功能,但這感覺就像在作弊。(請添加文檔也顯示如何...)
如何將參數傳遞給中的C# grpc 定義以便我們可以使用可選關鍵字?
謝謝!
參考解法
方法 1:
As for January 2021, the only ‑ yet hacky ‑ way around this is to make your proto filename (or a directory name) contain the string test_proto3_optional
, as pointed out by protobuf documentation:
If you try to run protoc on a file with proto3 optional fields, you will get an error because the feature is still experimental. [...] There are two options for getting around this error:
- Pass
‑‑experimental_allow_proto3_optional
to protoc.- Make your filename (or a directory name) contain the string
test_proto3_optional
. This indicates that the proto file is specifically for testing proto3 optional support, so the check is suppressed.
For more information see #977 (grpc‑dotnet), #19164 (AspNetCore.Docs) and #23686 (grpc) issues.
(by James Hancock、Sezi)