DEV Community

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

Posted on

1

'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!

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay