GRPC 可选消息不会生成字段存在属性

问题描述 投票:0回答:1

我正在使用

optional
检查现场是否存在。

例如

syntax = "proto3";

message ExampleClass{
    message ListFoo
    {
        repeated int64 foo = 1;
    }

    optional string name = 1;
    optional ListFoo foos = 2;
}

然后在C#代码中

属性

HasName
已生成,但
HasFoos
未生成?

他们似乎希望我们检查 null 。然而,在“可为空列表”的情况下,我仍然需要现场存在来确定是否意图将其设置为空。

那么在 grpc 中支持

nullable list
的最佳方式是什么?

c# .net-core grpc
1个回答
0
投票

在 proto3 中,

optional
对于类型为消息的字段没有任何意义。即使没有 optional,您也可以
始终
判断消息字段是否已设置。

要检查它是否在代码中设置,只需使用

if (message.Foos is not null)
。不需要
HasFoos
属性。

© www.soinside.com 2019 - 2024. All rights reserved.