Mapping to readonly array
See original GitHub issueIs your feature request related to a problem? Please describe. Protobuf compiler (protoc) generate class with fields which has only getter for arrays. Example
syntax = "proto3";
option csharp_namespace = "Test";
message TestMessage {
repeated int32 repeatedField = 1;
}
generate to
public sealed partial class TestMessage : pb::IMessage<TestMessage>
{
// skip many code
private readonly pbc::RepeatedField<int> repeatedField_ = new pbc::RepeatedField<int>();
public pbc::RepeatedField<int> RepeatedField {
get { return repeatedField_; }
}
// skip many code
}
Usualy this used as
var test = new TestMessage();
test.RepeatedField.Add(111);
test.RepeatedField.AddRange(new[] { 111, 222, 333 });
Now Mapperly ignore properties like that.
Describe the solution you’d like Add to generated code construction like
if (target.RepeatedField != null)
{
target.RepeatedField.AddRange(source.RepeatedField);
}
or
target.RepeatedField?.AddRange(source.RepeatedField);
Additional context Tested with latest version 2.6.0-next.3 Google.Protobuf version 3.21.12 Grpc.Tools version 2.50.0
Issue Analytics
- State:
- Created 8 months ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Why ReadOnlyArray<T> map method returns an T[] instead ...
ReadOnlyArray.map returns a new array with new array elements. You might want the new array elements to be readonly, you might not.
Read more >Creating a readonly array from another readonly array
Tuple-to-tuple mapping only works for homomorphic mapped types over a generic type. So type ArrTransform<T> = {[I in keyof T]: .
Read more >Read-Only Array and Tuple Types in TypeScript
Among TypeScript's many features are read-only array and tuple types, ... You can use mapped types to create read-only versions of custom arrays...
Read more >builtins.ReadonlyArray.map JavaScript and Node.js code ...
Best JavaScript code snippets using builtins.ReadonlyArray.map(Showing top 15 results out of 333) · JSDoc · Most used builtins functions · Popular in JavaScript....
Read more >Mapping readonly array to Zod union · Issue #831
I often use an as const array or object to simultaneously define types (guiding the compiler) AND sequences (used at runtime).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
🎉 This issue has been resolved in version 2.7.0-next.2 🎉
The release is available on:
v2.7.0-next.2
Your semantic-release bot 📦🚀
🎉 This issue has been resolved in version 2.7.0 🎉
The release is available on:
v2.7.0
Your semantic-release bot 📦🚀