fieldconverter c#
C#
//For fixed length records where you need to read decimal data and you don't have an explicit decimal dot (because this isn't required or a Cobol layout). You read it with a customer converter.
//If you want to parse a file with a field that has different parsing rules you can define a CustomConverter
[FixedLengthRecord]
public class PriceRecord
{
[FieldFixedLength(6)]
public int ProductId;
[FieldFixedLength(8)]
[FieldConverter(typeof(MoneyConverter))]
public decimal PriceList;
[FieldFixedLength(8)]
[FieldConverter(typeof(MoneyConverter))]
public decimal PriceEach;
}
//The last step is to define the converter, you must inherit from ConverterBase:
public class MoneyConverter : ConverterBase
{
public override object StringToField(string from)
{
return Convert.ToDecimal(Decimal.Parse(from) / 100);
}
public override string FieldToString(object fieldValue)
{
return ((decimal)fieldValue).ToString("#.##").Replace(".", "");
}
}
var engine = new FileHelperEngine<PriceRecord>();
var res = engine.ReadFile("Input.txt");
foreach (var product in res)
Console.WriteLine("Product {0} price {1}", product.ProductId, product.PriceList);
Also in C#:
- Title
- c# find duplicates in list
- Category
- C#
- Title
- raycast unity
- Category
- C#
- Title
- C# Cast double to float
- Category
- C#
- Title
- unity 2d top down movement
- Category
- C#
- Title
- c# ref
- Category
- C#
- Title
- convert from xls to xlsx C#
- Category
- C#
- Title
- C# assigning image location
- Category
- C#
- Title
- c# double value with 2 decimal places
- Category
- C#
- Title
- snippet to create constructor in asp.net c#
- Category
- C#
- Title
- reference to gameobject in different scene unity
- Category
- C#
- Title
- c# MD5.Create returning nul
- Category
- C#
- Title
- c# getter setter
- Category
- C#
- Title
- wpf get name of clicked element
- Category
- C#
- Title
- generate a dropdown list from array data using razor .net mvc
- Category
- C#
- Title
- c# create dynamic object
- Category
- C#
- Title
- weakreference tryget c#
- Category
- C#
- Title
- asp.net textarea disable resize
- Category
- C#
- Title
- how to delay something in c# unity
- Category
- C#
- Title
- never lose focus textbox c#
- Category
- C#
- Title
- c# make http request
- Category
- C#
- Title
- c# public static string
- Category
- C#
- Title
- how to change the title of the console in c#
- Category
- C#
- Title
- compose graphql query string in c#
- Category
- C#
- Title
- find month number from date C#
- Category
- C#
- Title
- leantween id
- Category
- C#
- Title
- unity object array
- Category
- C#
- Title
- c# ^ operator
- Category
- C#
- Title
- how to change player cursor c# script unity
- Category
- C#
- Title
- how get data from json in c#
- Category
- C#
- Title
- unity check tag
- Category
- C#
- Title
- c# arrays of arrays
- Category
- C#
- Title
- f string C#
- Category
- C#
- Title
- unity docs player input
- Category
- C#
- Title
- c# get last character of string
- Category
- C#
- Title
- c# how to exit program
- Category
- C#
- Title
- how to chagne rotation in unity
- Category
- C#
- Title
- c# get list of all class fields
- Category
- C#
- Title
- c# if statement
- Category
- C#
- Title
- open udp socket c#
- Category
- C#
- Title
- unity 2d enemy field of view
- Category
- C#
- Title
- unity jump
- Category
- C#
- Title
- how to create a list in c# unity
- Category
- C#
- Title
- c# making a folder
- Category
- C#
- Title
- create asp.net which send email and sms using own api
- Category
- C#
- Title
- c# download file
- Category
- C#
- Title
- unity instantiate
- Category
- C#
- Title
- find gameobject with tag
- Category
- C#
- Title
- creating a c# class
- Category
- C#
- Title
- matplotlib measure the width of text
- Category
- C#
- Title
- autoresetevent
- Category
- C#
- Title
- unity input get axis
- Category
- C#
- Title
- how to copy one array value to another without reference c#
- Category
- C#
- Title
- access object property C#
- Category
- C#
- Title
- c# for loop without increment
- Category
- C#
- Title
- how to find the type of a object c#
- Category
- C#
- Title
- C# how to get public key for InternalsVisibleTo
- Category
- C#
- Title
- c# get enum value from string
- Category
- C#
- Title
- c# int
- Category
- C#
- Title
- c# download string url
- Category
- C#
- Title
- transform.Translate movement
- Category
- C#
- Title
- count the number of notes in a given amount c#
- Category
- C#
- Title
- math class C# exponents
- Category
- C#
- Title
- C# get object property name
- Category
- C#
- Title
- uwp file open picker
- Category
- C#
- Title
- microsoft.portable.csharp.targets was not found vs 2019
- Category
- C#
- Title
- check connection c#
- Category
- C#
- Title
- how to a equall to b in c#
- Category
- C#
- Title
- c# lambda expression
- Category
- C#
- Title
- c# counting lines
- Category
- C#
- Title
- print content of array c#
- Category
- C#
- Title
- html hidden text
- Category
- C#
- Title
- unity main texture not working
- Category
- C#
- Title
- flip boolean c#
- Category
- C#
- Title
- c# find index element array
- Category
- C#
- Title
- dictionary c#
- Category
- C#
- Title
- how to make if statement c#
- Category
- C#
- Title
- c# loop
- Category
- C#
- Title
- Assets/Scripts/Snake.cs(177,25): error CS1061: Type `Snake.SnakeBodyPart' does not contain a definition for `SetGridPostion' and no extension method `SetGridPostion' of type `Snake.SnakeBodyPart' could be found. Are you missing an assembly reference?
- Category
- C#
- Title
- c# list string return concatenate
- Category
- C#
- Title
- downlaod file and use C#
- Category
- C#
- Title
- c# print expression tree
- Category
- C#
- Title
- c# convert utc to est
- Category
- C#
- Title
- how to make % posibility to spawn an object C# in unity
- Category
- C#
- Title
- application variable in asp.net core
- Category
- C#
- Title
- array c#
- Category
- C#
- Title
- Linq - Random Elements
- Category
- C#
- Title
- viewBag as a list
- Category
- C#
- Title
- how to remove vowels from a sttring using regex c#
- Category
- C#
- Title
- C# move form without border
- Category
- C#
- Title
- c# datatable copy selected rows to another table
- Category
- C#
- Title
- how to make a datatable in c#
- Category
- C#
- Title
- how to print statement in c#
- Category
- C#
- Title
- Rigidbody.addforce
- Category
- C#
- Title
- The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located.
- Category
- C#
- Title
- c# combobox datasource enum
- Category
- C#
- Title
- .net core get image from url
- Category
- C#
- Title
- how to make rb.addforce 2d
- Category
- C#
- Title
- c# create array of int
- Category
- C#
- Title
- c# expression func automatically select return type
- Category
- C#
- Title
- web api startup add imemory cache object
- Category
- C#