FixedWidthLibrary 0.3.1
See the version list below for details.
dotnet add package FixedWidthLibrary --version 0.3.1
NuGet\Install-Package FixedWidthLibrary -Version 0.3.1
<PackageReference Include="FixedWidthLibrary" Version="0.3.1" />
<PackageVersion Include="FixedWidthLibrary" Version="0.3.1" />
<PackageReference Include="FixedWidthLibrary" />
paket add FixedWidthLibrary --version 0.3.1
#r "nuget: FixedWidthLibrary, 0.3.1"
#:package FixedWidthLibrary@0.3.1
#addin nuget:?package=FixedWidthLibrary&version=0.3.1
#tool nuget:?package=FixedWidthLibrary&version=0.3.1
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/FalseValuesettings on theFixedWidthattribute. - 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
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- FixedWidthLibrary.Core (>= 0.3.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.