Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amarok79/amarok.shared
A library with commonly-used general-purpose types like helpers, utilities and extensions.
https://github.com/amarok79/amarok.shared
dotnet helpers utility
Last synced: about 1 month ago
JSON representation
A library with commonly-used general-purpose types like helpers, utilities and extensions.
- Host: GitHub
- URL: https://github.com/amarok79/amarok.shared
- Owner: Amarok79
- License: mit
- Created: 2019-05-21T20:12:17.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-06-30T09:33:36.000Z (6 months ago)
- Last Synced: 2024-10-30T21:48:49.074Z (2 months ago)
- Topics: dotnet, helpers, utility
- Language: C#
- Homepage:
- Size: 215 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![CI](https://github.com/Amarok79/Amarok.Shared/workflows/CI/badge.svg)
[![NuGet](https://img.shields.io/nuget/v/Amarok.Shared.svg?logo=)](https://www.nuget.org/packages/Amarok.Shared/)# Introduction
This library contains various general purpose helpers, utilities and extensions.
# Redistribution
The library is redistributed as NuGet package: [Amarok.Shared](https://www.nuget.org/packages/Amarok.Shared/)
The package provides strong-named binaries for *.NET Standard 2.0*, *.NET 6.0*, *.NET 7.0*, and *.NET 8.0*. Tests are
performed with *.NET Framework 4.8*, *.NET 6.0*, *.NET 7.0*, and *.NET 8.0*.# Types of Interest
### BufferSpan
A memory-efficient value type pointing to a span (segment) in a byte array. Provides APIs for appending or slicing.
Tuned to reduce memory allocations.````cs
var a = BufferSpan.From(0x11, 0x22);
var b = BufferSpan.From(new Byte[] { 0x22, 0x33, 0x44, 0x55, 0x66 }, 1, 3);b.Buffer // 0x22, 0x33, 0x44, 0x55, 0x66; same as supplied to From(..)
b.Offset // 1
b.Count // 3
b.IsEmpty // false
b.ToArray() // 0x33, 0x44, 0x55; allocates new byte array
b.ToString() // 33-44-55var c = a.Append(b); // 0x11, 0x22, 0x33, 0x44, 0x55; re-uses byte array if big enough,
// otherwise allocates new byte array
c = c.Discard(1); // 0x22, 0x33, 0x44, 0x55; re-uses byte array
c = c.Slice(1, 2); // 0x33, 0x44; re-uses byte array
c = c.Clear(); // , but re-uses the original byte array
````### Byte, Byte[] Extensions
Extension methods for efficient hex formatting.
````cs
Byte byte = 0x0F;
String text = byte.ToHex(); // "0x0F"Byte[] bytes = new[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA };
String text = bytes.ToHex(" "); // "0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xAA"
````### StopwatchPool
Provides a pool of pre-instantiated Stopwatch instances.
````cs
Stopwatch sw = null;
try
{
sw = StopwatchPool.Rent();// use stop watch
}
finally
{
StopwatchPool.Free(sw);
}
````### StringBuilderPool
Provides a pool of pre-instantiated StringBuilder instances.
````cs
StringBuilder sb = null;
try
{
sb = StringBuilderPool.Rent();// use string builder
var result = sb.ToString();
}
finally
{
StringBuilderPool.Free(sb);
}
````