question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mapping to readonly array

See original GitHub issue

Is 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:closed
  • Created 8 months ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
github-actions[bot]commented, Jan 26, 2023

🎉 This issue has been resolved in version 2.7.0-next.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

0reactions
github-actions[bot]commented, Mar 13, 2023

🎉 This issue has been resolved in version 2.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found