I'm programming in C# - still pretty new to this protobuf stuff
If you have the following proto file extending the EnumValueOptions:
extend google.protobuf.EnumValueOptions {
string Value = 101;
bool AutoEnrol = 102;
}
Protobuf will produce a EnumValueOptionsExtensions class through auto-generation.
To access it use EnumValueOptionsExtensions.Value or EnumValueOptionsExtensions.AutoEnrol, per the C# code sample a little later/below.
Then in the same or another proto file, create an enum with the following:
enum SystemRoleType {
ReservedRole = 0 [(Value) = "SystemRoleType.ReservedRole", (AutoEnrol) = false];
Administrator = 1001 [(Value) = "SystemRoleType.Administrator", (AutoEnrol) = false];
Editor = 1002 [(Value) = "SystemRoleType.Editor", (AutoEnrol) = false];
ContentCreator = 1003 [(Value) = "SystemRoleType.ContentCreator", (AutoEnrol) = false];
User = 1004 [(Value) = "SystemRoleType.ContentCreator", (AutoEnrol) = true];
}
Again, this will produce a SystemRoleTypeReflection class through protobuf auto-generation.
Then in C#, include your namespaces accordingly (that also includes: Google.Protobuf.Reflection) and then you could do something like the following in C#
EnumDescriptor SystemRoleTypeTypeEnumDescriptor = SystemRoleTypeReflection.Descriptor.FindTypeByName<EnumDescriptor>(typeof(SystemRoleType).Name);
foreach (SystemRoleType system_role_type in Enum.GetValues(typeof(SystemRoleType)))
{
EnumValueDescriptor enum_value_descriptor = SystemRoleTypeTypeEnumDescriptor.FindValueByNumber((int)system_role_type);
var selector_value = enum_value_descriptor.GetOptions().GetExtension<string>(EnumValueOptionsExtensions.Value);
var auto_enrolment = enum_value_descriptor.GetOptions().GetExtension<bool>(EnumValueOptionsExtensions.AutoEnrol);
}
Updated (2021-12-01):
I put a tiny VS solution together today, that you can open in Visual Studio Community 2022 (.Net 6 / C# 10) and run the example in a console app: github.com/kibblewhite/EnumValueOptions-gRPC-Example