Skip to content

Support C# 11 required modifier in Grpc.Tools #22304

Open
@lukedukeus

Description

@lukedukeus

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    untriagedauto added to all issues by default when created.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions