protocolbuffers / protocolbuffers/protobuf
Check for wrapper types in C# code gen should be case insensitive
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 72k
- Forks
- 16.3k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 140
Description
What version of protobuf and what language are you using?
Version: Gprc.Tools version 2.71.0
Language: C#
What operating system (Linux, Windows, ...) and version?
Windows
What runtime / compiler are you using (e.g., python version or gcc version)
What did you do?
Have a proto file like this:
syntax = "proto3";
option csharp_namespace = "Microsoft.AspNetCore.Grpc.JsonTranscoding.Tests.TestObjects.ProtobutMessages";
import "Google/protobuf/wrappers.proto";
import "Google/api/annotations.proto";
package test;
message WrappersMessage {
google.protobuf.StringValue string_value = 1;
google.protobuf.Int32Value int32_value = 2;
google.protobuf.Int64Value int64_value = 3;
google.protobuf.FloatValue float_value = 4;
google.protobuf.DoubleValue double_value = 5;
google.protobuf.BoolValue bool_value = 6;
google.protobuf.UInt32Value uint32_value = 7;
google.protobuf.UInt64Value uint64_value = 8;
google.protobuf.BytesValue bytes_value = 9;
}
It successfully compiles, but the properties generated on the C# type are StringValue rather than string.
This is because the import isn't completely lower case: import "Google/protobuf/wrappers.proto";. The code to detect if a field is a wrapper then checks the file name without ignoring case:
What did you expect to see
string field:
/// <summary>Field number for the "string_value" field.</summary>
public const int StringValueFieldNumber = 1;
private static readonly pb::FieldCodec<string> _single_stringValue_codec = pb::FieldCodec.ForClassWrapper<string>(10);
private string stringValue_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string StringValue {
get { return stringValue_; }
set {
stringValue_ = value;
}
}
What did you see instead?
StringValue field:
/// <summary>Field number for the "string_value" field.</summary>
public const int StringValueFieldNumber = 1;
private global::Google.Protobuf.WellKnownTypes.StringValue stringValue_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public global::Google.Protobuf.WellKnownTypes.StringValue StringValue {
get { return stringValue_; }
set {
stringValue_ = value;
}
}
Anything else we should know about your project / environment
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/google/protobuf/compiler/csharp/csharp_helpers.h at the wrapper-type detection around lines 112-115, then reproduce the case-sensitive import using the proto shown in the issue. Verify the C# generator recognizes Google/protobuf/wrappers.proto regardless of import casing and produces the primitive string property shown under the expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 82/100