You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[...] if you return an array from a method instead of a property it won't work even if the two are functionally equivalent. For example Quire.Segments is an array returning property which is not suggested for performance reasons. But if I replace it with a ulong[] GetSegments() => _segments; method, I will get the The length of the array holder System.Void Lombiq.Arithmetics.Quire::.ctor(System.UInt64[],System.UInt16).Lombiq.Arithmetics.Quire.GetSegments (@this)[82..87) couldn't be statically determined. error. Checking if a method returns a trivial reference could resolve that problem.
We need:
ulong[] GetSegments() => _segments.Clone(); : return the clone of an array backing field from a function.
IReadOnlyList<ulong> GetSegments() => _segments; : return the backing field directly as an immutable collection.
public IReadOnlyList<ulong> Segments => _segments; : do the same from a get-only property.
Following up here. Yep, we'd need to support those three scenarios indeed. IReadOnlyList<T> should be fairly straightforward since we don't actually need to do anything with it on the hardware, it can be an array (since write access to it is prevented in the .NET level already).
github-actionsbot
changed the title
Add support for returning an array field (or its clone) from methods
Add support for returning an array field (or its clone) from methods (HAST-258)
Sep 18, 2022
As mentioned here:
We need:
ulong[] GetSegments() => _segments.Clone();
: return the clone of an array backing field from a function.IReadOnlyList<ulong> GetSegments() => _segments;
: return the backing field directly as an immutable collection.public IReadOnlyList<ulong> Segments => _segments;
: do the same from a get-only property.Jira issue
The text was updated successfully, but these errors were encountered: