|
Note: VB.NET developers browse the Tips for
VB.NET first.
Attributes List
Attributes for the record mapping class
- FixedLengthRecord: Indicates a fixed length record file.
[FixedLengthRecord]
public class OrdersFixed
{ ...
- DelimitedRecord: Indicates a delimited record file.
[DelimitedRecord("|")]
public class OrdersVerticalBar
{ ...
- IgnoreFirst: Indicates the
numbers of lines to be ignored at the begining of a file or
stream when the engine read it.
[IgnoreFirst(2)]
public class OrdersVerticalBar
{ ...
- IgnoreLast: Indicates the
numbers of lines to be ignored at the end of a file or stream
when the engine read it.
[IgnoreLast(2)]
public class OrdersVerticalBar
{ ...
- IgnoreEmptyLines: Indicates that the empty lines (only contains a NewLine) must be ignored by the engine.
[IgnoreEmptyLines()]
public class NotEmptyPlease
{ ...
- ConditionalRecord:
Allow you to add some conditions to tell the library what records to
process or not in a declarative way. using one of the
RecordCondition Enum and a string selector. Useful to ignore commented or
similar files.
[DelimitedRecord(",")]
[ConditionalRecord(RecordCondition.ExcludeIfBegins, "//")]
public class ConditionalType1
{
// Regular Expressions [DelimitedRecord(",")]
[ConditionalRecord(RecordCondition.IncludeIfMatchRegex, ".*abc??")]
public class ConditionalType3
{
Attributes for the fields inside the class
All the attributes for the Fields begin with [Field.. then you can easy found all of them.
- FieldFlixedLength: Indicates the length of the record (only valid when the class have a FixedLengthRecord)
[FieldFixedLength(12)]
public string CustomerID;
- FieldDelimiter: Indicates a diferent delimiter for this field (only valid when the class have a DelimitedRecord)
[FieldDelimiter(",")]
public string CustomerName;
- FieldConverter: Indicates converter used to to provide string to field type convertion and viceversa. And can add a list of parameters that pass directly to the constructor of the converter, in the example is a string that represents a format of the Date field.
[FieldConverter(ConverterKind.Date, "ddMMyyyy" )]
public DateTime ShippedDate;
[FieldConverter(typeof(YourCustomConverter)))]
public YourType CustomTypeField;
Remember: The fault types are auto converted, so don't need the explicit [FieldConverter] use it only when you
need to pass them some argument. Check out the Default Converters Arguments Page.
You can see also the Custom Converter Example
- FieldQuoted: Indicates that the field must be read and written like a Quoted String. (you can pass the quote char and can set if the quote is optional like the Excel CSV format)
[FieldQuoted()] // Quoted with "
public string CustomerName
[FieldQuoted('[')] // Quoted between [brakets]
public string CustomerName
[FieldQuoted('"', QuoteMode.OptionalForBoth)] // Optional quoted when read or write
public string CustomerName
[FieldQuoted('"', MultilineMode.AllowForBoth)] // Indicates that the quoted string can span multiple lines
public string CustomerName
- FieldNullValue: Indicates a default value is the field position is empty.
[FieldNullValue(typeof(DateTime), "2005-1-1" )]
public DateTime ShippedDate
- FieldTrim: Indicates what type of trim must be perfomed later of read a field value (see TrimMode).
[FieldTrim(TrimMode.Both)]
public string CustomerName
- FieldAlign: Indicates what type of aligment and align char that must be used before write a field value (see AlignMode).
[FieldAlign(AlignMode.Right, '0')]
public int Going_to_the_Right
- FieldIgnored: Indicates that
the target field is ignored by the engine. (the engine completely ignore it !!). Is useful when you need to add a field to your record class but it is not relevant for the mapping.
[FieldIgnored()]
public int Why_Ignore_Me
- FieldInNewLine: Indicates that
before the field value is a New Line.
If you use this attribute the library request that new line that not is optional.
[FieldInNewLine()]
public string I_Wanna_Stay_Alone
- FieldOptional: Indicates that
the target field can stay or not in the file.
When you apply this attribute to a field, you must apply it to the following ones.
[FieldOptional()]
public string Maybe_I_be_there
See also
Must Read - Quick Start Guide - Attributes
List - F.A.Q. - Examples of
Use - Contacts & Credits - Donations
Powered by:
|