Skip to content

Repository files navigation

RANA.FileGenerator

Rana.FileGenerator is a library to simplify the generation of structured text files. Using an easily approach to make life easier. RANA uses customs annotations to mark how do you want to generate each field/property of a class, and it follows the rules in generation.

Example

Goal

|Product|00001|Name_____|00015.13|01/29/2020|

Code Using RANA

Declaring class/Entity/Model
public class ExampleReadme : LineContent
{
  [StringValue(Index = 0)]
  public string Description { get; set; }

  [NumericValue(Index = 1,Size = 5, PaddingOrientation = PaddingOrientation.Left, PaddingChar = '0')]
  public int Id { get; set; }

  [StringValue(Index = 2, Size = 9, PaddingOrientation = PaddingOrientation.Right, PaddingChar = '_')]
  public string Name { get; set; } 

  [DecimalValue(Index = 3,Precision = 2,UseDecimalChar = true, Size = 8, PaddingChar = '0')]
  public decimal Price { get; set; }

  [DateTimeValue(Index = 3,DateFormat = "MM/dd/yyyy")]
  public DateTime DateAdded { get; set; }
}

Calling generation of one line

ExampleReadme testObject = new ExampleReadme
{
  Description = "Product",
  Id = 1,
  Name = "Name",
  Price = 15.13M,
  DateAdded = new DateTime(2020, 01, 29)
};

testObject.Generate("Product","|",separatorAtBegining: true,separatorAtEnd: true);

Calling generation of multiples lines

The example showed how to generate one line, but if you want to generate the whole file, there is a list called ListFileContent that do it for you. Following example:

ListFileContent<ExampleReadme> linesOfTheFile = new ListFileContent<ExampleReadme>();
linesOfTheFile.Generate("Product", "|", separatorAtBegining: true, separatorAtEnd: true);

Both examples are at the unit tests, #1 First example is called GenerateReadmeExample and the #2 second GenerateListReadmeExample.

About

File generator

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages