Skip to content

Commit 72ea87f

Browse files
Provide Microsoft.Bcl.Memory package readme (#106273)
* Provide Microsoft.Bcl.Memory package readme * Update Microsoft.Bcl.Memory.csproj * Fix small issues --------- Co-authored-by: Viktor Hofer <[email protected]>
1 parent 380898a commit 72ea87f

File tree

2 files changed

+84
-11
lines changed

2 files changed

+84
-11
lines changed

src/libraries/Microsoft.Bcl.Memory/src/Microsoft.Bcl.Memory.csproj

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,7 @@
99
Once this package has shipped a stable version, the following line
1010
should be removed in order to re-enable validation. -->
1111
<DisablePackageBaselineValidation>true</DisablePackageBaselineValidation>
12-
<PackageDescription>
13-
Provides Base64Url encoding, decoding and validation APIs support for .NET Framework and .NET Standard.
14-
Provides Index and Range types support for .NET Framework and .NET Standard 2.0.
15-
16-
Commonly Used Types:
17-
System.Buffers.Text.Base64Url
18-
System.Index
19-
System.Range
20-
</PackageDescription>
21-
<!-- TODO: Add package README file: https://github.com/dotnet/runtime/issues/99358 -->
22-
<EnableDefaultPackageReadmeFile>false</EnableDefaultPackageReadmeFile>
12+
<PackageDescription>Provides Base64Url, Index and Range types support for .NET Framework and .NET Standard.</PackageDescription>
2313
</PropertyGroup>
2414

2515
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
## About
2+
3+
Provides `Index` and `Range` types to simplify slicing operations on collections for .NET Framework and .NET Standard 2.0.
4+
Provides `Base64Url` for encoding data in a URL-safe manner on .NET Framework and .NET Standard.
5+
6+
This library is not necessary nor recommended when targeting versions of .NET that include the relevant support.
7+
8+
## Key Features
9+
10+
<!-- The key features of this package -->
11+
12+
* Enables the use of `Index` and `Range` types on older .NET platforms.
13+
* Provides `Base64Url` encoding, decoding, and validation for URL-safe data processing on older .NET platforms.
14+
15+
## How to Use
16+
17+
<!-- A compelling example on how to use this package with code, as well as any specific guidelines for when to use the package -->
18+
19+
The `Index` and `Range` types simplify working with slices of arrays, strings, or other collections.
20+
21+
```csharp
22+
string[] words = ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"];
23+
24+
// Use Index to reference the last element
25+
Console.WriteLine(words[^1]);
26+
// Output: "dog"
27+
28+
// Use Range to reference a slice
29+
string[] phrase = words[1..4];
30+
Console.WriteLine(string.Join(" ", phrase));
31+
// Output: "quick brown fox"
32+
```
33+
34+
`Base64Url` encoding is a URL-safe version of Base64, commonly used in web applications, such as JWT tokens.
35+
36+
```csharp
37+
using System.Buffers.Text;
38+
using System.Text;
39+
40+
// Original data
41+
byte[] data = Encoding.UTF8.GetBytes("Hello World!");
42+
43+
Span<byte> encoded = new byte[Base64Url.GetEncodedLength(data.Length)];
44+
Base64Url.EncodeToUtf8(data, encoded, out int _, out int bytesWritten);
45+
46+
string encodedString = Base64Url.EncodeToString(data);
47+
Console.WriteLine($"Encoded: {encodedString}");
48+
// Encoded: SGVsbG8gV29ybGQh
49+
50+
Span<byte> decoded = new byte[data.Length];
51+
Base64Url.DecodeFromUtf8(encoded[..bytesWritten], decoded, out _, out bytesWritten);
52+
53+
string decodedString = Encoding.UTF8.GetString(decoded[..bytesWritten]);
54+
Console.WriteLine($"Decoded: {decodedString}");
55+
// Decoded: Hello World!
56+
```
57+
58+
## Main Types
59+
60+
<!-- The main types provided in this library -->
61+
62+
The main types provided by this library are:
63+
64+
* `System.Index`
65+
* `System.Range`
66+
* `System.Buffers.Text.Base64Url`
67+
68+
## Additional Documentation
69+
70+
<!-- Links to further documentation. Remove conceptual documentation if not available for the library. -->
71+
72+
API documentation
73+
74+
* [System.Index](https://learn.microsoft.com/dotnet/api/system.index)
75+
* [System.Range](https://learn.microsoft.com/dotnet/api/system.range)
76+
* [System.Buffers.Text.Base64Url](https://learn.microsoft.com/dotnet/api/system.buffers.text.base64url)
77+
78+
## Feedback & Contributing
79+
80+
<!-- How to provide feedback on this package and contribute to it -->
81+
82+
Microsoft.Bcl.Memory is released as open source under the [MIT license](https://licenses.nuget.org/MIT).
83+
Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime).

0 commit comments

Comments
 (0)