Runtime: Add Guid.GetBytes(byte[]) and Decimal.GetBits(decimal d, byte[])

Created on 15 Oct 2016  Â·  9Comments  Â·  Source: dotnet/runtime

@davidfowl commented on Sun Sep 18 2016

Today the supported way to get the byte[] representation of a guid is to use ToByteArray() https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/Guid.cs#L893, which allocates a byte[]. Instead it would be great if there was an overload that could write into an existing byte[]


@mikedn commented on Mon Sep 19 2016

Guid.GetBytes(Span<byte>)?


@davidfowl commented on Sun Sep 25 2016

Would be even better. When Span<T> exists

api-needs-work area-System.Runtime up-for-grabs

Most helpful comment

I see there's a couple specific requests for this, but it's more of a general problem. Should we look at all functions that can copy to new arrays and consider adding overloads that copy to an existing array?

All 9 comments

Moved from CoreCLR as it's an API addition.

https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/contributing.md says:

Please use the following general rule-of-thumb for choosing the right repo to make your change (start by creating an issue):
• The type or concept doesn't yet exist in .NET Core -> choose CoreFX.
• The type exists in both CoreCLR and CoreFX repo -> choose CoreFX.
• The type exists in CoreCLR only -> choose CoreCLR.
• In doubt -> choose CoreFX.

We need formal API proposal

I see there's a couple specific requests for this, but it's more of a general problem. Should we look at all functions that can copy to new arrays and consider adding overloads that copy to an existing array?

Yes 😄

We should probably wait first for the Span<T> discussion to finish. Then we will know what is the desired pattern we want in the APIs.

For tracking the more general issue, I would suggest filing a new issue with list of all such APIs. (someone needs to do a larger sweep) We can then decide to close this one.

Why do we need to wait for the Span design to complete. In this case as well as in the cases where we use StringBuilders under the hood, enabling an overload that lets people pass in the array or StringBuilder to use instead seems like a good improvement to the API. Would we wait for Span to see if thats what we want to enable passing to the overload?

Would we wait for Span to see if thats what we want to enable passing to the overload?

Yes, that's the idea.

It sounds like the first step would be to identify all the types where we would like to have these additions on. Anyone interested?

Moved tracking to dotnet/corefx#13892.

Was this page helpful?
0 / 5 - 0 ratings