A focused collection of high-performance extension methods for common .NET 10 types, with first-class support for Ethereum-style 256-bit word encoding, hexadecimal parsing, Brotli compression, and JSON converters for BigInteger and byte[].
Targets net10.0 and uses C# 14 extension blocks for ergonomic call sites such as Bytes.ToUInt256() and "0xabc".HexToInt64().
dotnet add package Texnomic.Types.ExtensionsusingTexnomic.Types.Extensions;byte[]Bytes="0xdeadbeef".HexToBytes();intI32="0x1a".HexToInt32();// 26BigIntegerU256="0xff...ff".HexToUInt256();// 2^256 - 1ReadOnlySpan<byte>Payload= ...;// ABI-encoded return dataBigInteger[]Words=Payload.ToUInt256Array();// one BigInteger per 32-byte wordBigIntegerFirst=Payload.TakeWord().ToUInt256();BigIntegerNext=Payload.SkipWord().TakeWord().ToUInt256();BigIntegerAddress= ...;stringHex=Address.AsPaddedHex(Width:20);// 40-char hex, "0x000...000abc"byte[]Hash= ...;stringBytes32=Hash.AsPaddedHex(Width:32);// 64-char hexusingTexnomic.Types.Extensions.Json;usingSystem.Text.Json;varOptions=newJsonSerializerOptions{Converters={newHexBigIntegerJsonConverter(),newHexByteArrayJsonConverter(),},};// Round-trips "0x..." strings as BigInteger / byte[] transparently.varBlock=JsonSerializer.Deserialize<EvmBlock>(Json,Options);Both converters read and write 0x-prefixed lowercase hexadecimal — the canonical Ethereum JSON-RPC data / quantity format.
Span<byte>Buffer=stackallocbyte[32];if(Value.TryWriteBytes(Buffer,outvarWritten,IsBigEndian:true)){// 'Written' bytes of the encoded payload are now in Buffer.}Available on int, uint, long, ulong, BigInteger, and bool.
byte[]Compressed=Payload.Compress();byte[]Decompressed=Compressed.Decompress();// Async equivalentsbyte[]Zipped=awaitPayload.CompressAsync();byte[]Unzipped=awaitZipped.DecompressAsync();ReadOnlySpan<byte>Data= ...;ReadOnlySpan<byte>Pattern= ...;intOffset=Data.BoyerMooreIndexOf(Pattern);// -1 if no match (IndexOf-style)List<int>All=Data.BoyerMooreSearch(Pattern);// every occurrenceFunc<Task<int>>Work=async()=>awaitComputeAsync();intResult=Work.RunSync();// runs on TaskScheduler.Default, no captured contextawaitSocket.SendJsonAsync(Request,JsonOptions,CancellationToken);Memory<byte>Buffer=newbyte[64*1024];varResponse=awaitSocket.ReceiveJsonAsync<MyResponse>(Buffer,JsonOptions,CancellationToken);publicstaticMyDtoRead(refUtf8JsonReaderReader){varSymbol=Reader.GetStringOptimized();// interned via StringPool.SharedvarValue=Reader.GetHexUInt256();// "0x..." → BigIntegerreturnnewMyDto(Symbol,Value);}| Source file | Target type | Highlights |
|---|---|---|
AsyncExtensions.cs | Func<Task>, Func<Task<T>>, Task<T> | RunSync() |
BigIntegerExtensions.cs | BigInteger | ToBigDecimal, ToBytes, TryWriteBytes, AsHex, AsPaddedHex |
BoolExtensions.cs | bool | ToBytes, TryWriteBytes, AsHex |
ByteArrayExtensions.cs | byte[] | Span/memory projections, 256-bit decoding, hex / AsPaddedHex / Base64, Brotli compression (sync + async) |
ByteReadOnlySpanExtensions.cs | ReadOnlySpan<byte> | + TakeWord / SkipWord + BoyerMooreSearch / BoyerMooreIndexOf |
ByteSpanExtensions.cs | Span<byte> | Writable-span variant |
ClientWebSocketExtensions.cs | ClientWebSocket | SendJsonAsync / ReceiveJsonAsync |
DecimalExtensions.cs | decimal | AsHex |
IntegerExtensions.cs | int, uint | ToBytes, TryWriteBytes, AsHex |
LongExtensions.cs | long, ulong | ToBytes, TryWriteBytes, AsHex |
ReadOnlySpanExtensions.cs | ReadOnlySpan<T> | Take / Skip + bounds-safe SafeTake / SafeSkip |
SpanExtensions.cs | Span<T> | Take / Skip |
StringExtensions.cs | string | RemoveHexPrefix, hex parsing to bytes / BigDecimal / 32/64/256-bit ints |
StringReadOnlySpanExtensions.cs | ReadOnlySpan<char> | Zero-allocation hex parsing |
Utf8JsonReaderExtensions.cs | Utf8JsonReader | Hex-token decoders, GetStringOptimized (StringPool.Shared) |
Json/HexBigIntegerJsonConverter.cs | BigInteger | JsonConverter<BigInteger> — 0x-prefixed lowercase hex |
Json/HexByteArrayJsonConverter.cs | byte[] | JsonConverter<byte[]> — 0x-prefixed lowercase hex |
| Package | Purpose |
|---|---|
CommunityToolkit.HighPerformance | StringPool for allocation-free repeated string reads. |
ExtendedNumerics.BigDecimal | Arbitrary-precision decimal arithmetic used by ToBigDecimal / HexToBigDecimal. |
Throw | Fluent argument validation. |
git clone https://github.com/Texnomic/Types.Extensions
cd Types.Extensions
dotnet build
dotnet test
dotnet pack -c ReleaseRun benchmarks:
dotnet run --project Benchmarks/Texnomic.Types.Extensions.Benchmarks -c Release -- --filter '*'MIT © Texnomic.