Coder Social home page Coder Social logo

Comments (7)

JoshClose avatar JoshClose commented on June 2, 2024

Hmm... I think I would create a new parser for this. Parsing will be completely different. Writing will also be different, so I may have to abstract some of the writing stuff out too.

from csvhelper.

paulduran avatar paulduran commented on June 2, 2024

@roryprimrose I think you'd be better off going with something like FileHelpers for fixed width file parsing. It already supports fixed width files pretty well.

from csvhelper.

JoshClose avatar JoshClose commented on June 2, 2024

I think there would be too many things that need to be added here for this to work properly. There would need to be a FixedWidthParser written. The property configurations would need at least the width set on them. This will muddy up the api. I think creating a whole new library that works with fixed width files is a better idea.

If that does happen and there is enough overlap in the reader and writer (i.e. auto class generation), maybe something could be abstracted out to be used in both libraries.

Right now this is not something I'm going to pursue.

from csvhelper.

JoshClose avatar JoshClose commented on June 2, 2024

I'm thinking I may add this to version 3.0.

from csvhelper.

dmitry-azaraev avatar dmitry-azaraev commented on June 2, 2024

@JoshClose I'm add ability of writing fixed-length fields, implementation now https://github.com/dmitry-azaraev/CsvHelper/tree/feature/writing-fixed-length-records .

It is actually do next things:

  • Allow use empty delimeter. (Alternatively it is enough to make own CsvSerializer and do not emit delimeters).
  • (Not directly related): Constants uses type converters. Current versions falls on Map().Constant(123). I'm fix it to always invoke type converters even for constants.
  • Allow configure CsvPropertyMap Width, Align and AlignErrorMode for writing fixed-length fields.
  • Added some tests about using width, align and error mode.

Basic idea of usage is:

    // configure 
    configuration.Delimiter = "";
    configuration.QuoteNoFields = true;
    configuration.HasHeaderRecord = false;

    // in map, define mappings
    Map(m => m.Id).Width(5);
    // or 
    Map(m => m.Id).Width(5, CsvAlign.Right);  // will pad spaces from left
    // or
    Map(m => m.Id).Width(5, CsvAlign.Right, CsvAlignErrorMode.Throw);  // will throw if field is not fit in space

Even while it is only supports writing, i'm found that it is simpler keep using one CsvHelper because when i'm write files, i'm use same fluent mapping syntax, reuse formats / etc. Do you like something like this?

And can i'm (we) count to have similar functionality in nearest future. I.e. what i'm should do to have PR been accepted?

from csvhelper.

JoshClose avatar JoshClose commented on June 2, 2024

This issue was moved to CsvHelperContrib/CsvHelperContrib#2

from csvhelper.

niemyjski avatar niemyjski commented on June 2, 2024

+1

from csvhelper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.