FixedWidthLibrary 0.3.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package FixedWidthLibrary --version 0.3.1
                    
NuGet\Install-Package FixedWidthLibrary -Version 0.3.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FixedWidthLibrary" Version="0.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FixedWidthLibrary" Version="0.3.1" />
                    
Directory.Packages.props
<PackageReference Include="FixedWidthLibrary" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FixedWidthLibrary --version 0.3.1
                    
#r "nuget: FixedWidthLibrary, 0.3.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FixedWidthLibrary@0.3.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FixedWidthLibrary&version=0.3.1
                    
Install as a Cake Addin
#tool nuget:?package=FixedWidthLibrary&version=0.3.1
                    
Install as a Cake Tool

FixedWidthLibrary

Roslyn analyzer and source generator that builds high-performance readers and writers for fixed-width flat-file records from simple attributes. Pair this with FixedWidthLibrary.Core which provides the runtime attributes and types.

Install

Reference both packages in your project:

dotnet add package FixedWidthLibrary.Core
dotnet add package FixedWidthLibrary

The analyzer/source generator runs at build time; no code changes are required beyond adding attributes.

Define a record
using FixedWidthLibraryCore.FixedWidthMarker;
using FixedWidthLibraryCore.FixedWidth;

[FixedWidthMarker]
public partial class OrderLine
{
    [FixedWidth(0, 8)]
    public string Sku { get; set; }

    [FixedWidth(8, 5)]
    public int Quantity { get; set; }

    [FixedWidth(13, 1, TrueValue = "Y", FalseValue = "N")]
    public bool Backordered { get; set; }
}

During build, the generator produces parsing and serialization members so you can do:

var line = "ABC12345" + "00010" + "N" + "\r\n"; // width: 8 + 5 + 1
var record = new OrderLine(line);
// record.Sku == ABC12345; record.Quantity == 10; record.Backordered == false

var output = record.WriteToStringBuilder().ToString(); // Serialized fixed-width line
Notes
  • Start positions are zero-based and lengths are fixed. The generator uses the provided offsets to slice input and to write padded output.
  • Boolean fields can be mapped using TrueValue/FalseValue settings on the FixedWidth attribute.
  • Use WriteToStringBuilder() or stream helpers generated for efficient output.
Packages
  • FixedWidthLibrary (this package): analyzer + source generator.
  • FixedWidthLibrary.Core: attributes and runtime helpers consumed by your app and used by the generator.
Attributes reference

For a complete list of all attributes and options you can use on your models (including constructor parameters, defaults, and typed variants like FixedWidthInt, FixedWidthDateTime, FixedWidthBool, etc.), see the Attributes reference in the Core package README:

  • FixedWidthLibrary.Core → "Attributes reference" section
License

MIT

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.2 71 1/16/2026
0.3.1 55 1/16/2026
0.3.0 88 12/31/2025
0.1.0 90 12/26/2025