DEV Community

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

Posted on

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

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.

Top comments (1)

Collapse
 
pbouillon profile image
Pierre Bouillon

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