-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Provide Microsoft.Bcl.Memory package readme #106273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| ## About | ||
|
|
||
| Provides `Index` and `Range` types to simplify slicing operations on collections for .NET Framework and .NET Standard 2.0. | ||
| Provides `Base64Url` for encoding data in a URL-safe manner on .NET Framework and .NET Standard. | ||
|
|
||
| This library is not necessary nor recommended when targeting versions of .NET that include the relevant support. | ||
|
|
||
| ## Key Features | ||
|
|
||
| <!-- The key features of this package --> | ||
|
|
||
| * Enables the use of `Index` and `Range` types on older .NET platforms. | ||
| * Provides `Base64Url` encoding, decoding, and validation for URL-safe data processing on older .NET platforms. | ||
|
|
||
| ## How to Use | ||
|
|
||
| <!-- A compelling example on how to use this package with code, as well as any specific guidelines for when to use the package --> | ||
|
|
||
| The `Index` and `Range` types simplify working with slices of arrays, strings, or other collections. | ||
|
|
||
| ```csharp | ||
| string[] words = ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"]; | ||
|
|
||
| // Use Index to reference the last element | ||
| Console.WriteLine(words[^1]); | ||
| // Output: "dog" | ||
|
|
||
| // Use Range to reference a slice | ||
| string[] phrase = words[1..4]; | ||
| Console.WriteLine(string.Join(" ", phrase)); | ||
| // Output: "quick brown fox" | ||
| ``` | ||
|
|
||
| `Base64Url` encoding is a URL-safe version of Base64, commonly used in web applications, such as JWT tokens. | ||
|
|
||
| ```csharp | ||
| using System.Buffers.Text; | ||
| using System.Text; | ||
|
|
||
| // Original data | ||
| byte[] data = Encoding.UTF8.GetBytes("Hello World!"); | ||
|
|
||
| Span<byte> encoded = new byte[Base64Url.GetEncodedLength(data.Length)]; | ||
| Base64Url.EncodeToUtf8(data, encoded, out int _, out int bytesWritten); | ||
|
|
||
| string encodedString = Encoding.UTF8.GetString(encoded[..bytesWritten]); | ||
| Console.WriteLine($"Encoded: {encodedString}"); | ||
| // Encoded: SGVsbG8gV29ybGQh | ||
|
|
||
| Span<byte> decoded = new byte[data.Length]; | ||
| Base64Url.DecodeFromUtf8(encoded[..bytesWritten], decoded, out _, out bytesWritten); | ||
|
|
||
| string decodedString = Encoding.UTF8.GetString(decoded[..bytesWritten]); | ||
| Console.WriteLine($"Decoded: {decodedString}"); | ||
| // Decoded: Hello World! | ||
| ``` | ||
|
|
||
| ## Main Types | ||
|
|
||
| <!-- The main types provided in this library --> | ||
|
|
||
| The main types provided by this library are: | ||
|
|
||
| * `System.Index` | ||
| * `System.Range` | ||
| * `System.Buffers.Text.Base64Url` | ||
|
|
||
| ## Additional Documentation | ||
|
|
||
| <!-- Links to further documentation. Remove conceptual documentation if not available for the library. --> | ||
|
|
||
| API documentation | ||
|
|
||
| * [System.Index](https://learn.microsoft.com/dotnet/api/system.index) | ||
| * [System.Range](https://learn.microsoft.com/en-us/dotnet/api/system.range) | ||
| * [System.Buffers.Text](https://learn.microsoft.com/dotnet/api/system.buffers.text) | ||
eNeRGy164 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Feedback & Contributing | ||
|
|
||
| <!-- How to provide feedback on this package and contribute to it --> | ||
|
|
||
| Microsoft.Bcl.Memory is released as open source under the [MIT license](https://licenses.nuget.org/MIT). | ||
| Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime). | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.