'optional string' in proto3 messages will not yield nullable strings in C#
Justin Etighe

Justin Etighe @dystopiandev

About: I write code. ¯\_(ツ)_/¯

Location:
Nigeria
Joined:
Apr 3, 2019

'optional string' in proto3 messages will not yield nullable strings in C#

Publish Date: Nov 3 '22
1 1
syntax = "proto3";
import "google/protobuf/wrappers.proto";

message Sample {
  // this will throw if you don't pass at least an empty string in generated C# code
  optional string not_nullable = 1;

  // this wrapper generates `string?` in C# (as one would expect)
  google.protobuf.StringValue nullable = 2;
}
Enter fullscreen mode Exit fullscreen mode

That's all. Hopefully this saves you some WTFs/minute.

Comments 1 total

  • Pierre Bouillon
    Pierre BouillonNov 4, 2022

    This is good to know, pretty sure it will become handy someday, thanks!

Add comment