Open
Description
C# 11 adds properties that can be marked as required - https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/required.
When a property is required, it must be set in the object initializer. If a protobuf message does not mark a property as optional, it should be required in C#. Right now, I can do:
TestMessage.proto
:
syntax = "proto3";
message TestMessage {
int32 non_optional_property = 1;
optional int32 optional_property = 2;
}
Test.cs
:
TestMessage test= new TestMessage()
{
};
And I don't get any build errors. Instead, what I would expect is:
Required member 'TestMessage.NonOptionalProperty' must be set in the object initializer or attribute constructor.
Additional context
Very similar to 20729