Getting Started
Spinner is a high-performance library for converting objects to/from positional (fixed-width) strings. With version 2.0, Spinner delivers up to 79x faster performance and 26x less memory allocation compared to v1.x.
Prerequisites
Spinner is compatible with the following versions of .NET: .NET 10(LTS), .NET 9, .NET 8(LTS).
dotnet version 3.1, 5, 6 and 7 support was discontinued in spinner version 2.
Version 2.0 introduces major performance improvements:
- 60x faster read operations
- 31x faster write operations
- Up to 26x less memory allocation
See the Performance Benchmarks page for detailed results.
Installation
Spinner is distributed as a NuGet package. See the spinner for more information.
dotnet add package Spinner
Import Spinner
After installing the package, you'll need to import the Spinner class into your code.
using Spinner;
Configuring an Object
For a comprehensive understanding of how to configure your object, refer to the example
Using Spinner
Creating a Spinner Instance
Create a single Spinner<T> instance and reuse it for better performance:
var spinner = new Spinner<Nothing>();
Spinner<T> instances are thread-safe and can be reused across multiple operations and threads. Create one instance per type and reuse it throughout your application.
Writing Objects to Strings
Execute WriteAsString to obtain the mapped object as a string, or use WriteAsSpan to retrieve the result as a span.
var nothing = new Nothing("spinner", "www.spinner.com.br");
var spinner = new Spinner<Nothing>();
var stringResponse = spinner.WriteAsString(nothing);
//output: " spinner www.spinner.com.br"
var nothing = new Nothing("spinner", "www.spinner.com.br");
var spinner = new Spinner<Nothing>();
var spanResponse = spinner.WriteAsSpan(nothing);
//output: " spinner www.spinner.com.br"
Reading Strings to Objects
Use ReadFromString to parse a positional string into an object, or ReadFromSpan for better performance with span-based processing.
var spinner = new Spinner<NothingReader>();
var obj = spinner.ReadFromString(" spinner www.spinner.com.br");
//obj.Name = "spinner"
//obj.WebSite = "www.spinner.com.br"
var spinner = new Spinner<NothingReader>();
ReadOnlySpan<char> data = " spinner www.spinner.com.br".AsSpan();
var obj = spinner.ReadFromSpan(data);
//obj.Name = "spinner"
//obj.WebSite = "www.spinner.com.br"
ReadFromSpan is more efficient than ReadFromString as it avoids string allocations. Prefer this method in performance-critical scenarios.
Next Steps
- Learn about Writing Objects
- Learn about Reading Strings
- Explore Interceptors for custom value processing
- Check out Advanced Features for performance optimizations and additional capabilities