First, you need to make all of your fields optionally quoted.
[DelimitedRecord(",")]
public class contactTemplate
{
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string firstName;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string lastName;
}
Then you need to quote all the fields which contain an escaped character. You can use a BeforeReadRecord
event for this.
FileHelperEngine engine = new FileHelperEngine(typeof(contactTemplate));
engine.BeforeReadRecord += BeforeEvent;
private void BeforeEvent(EngineBase engine, BeforeReadRecordEventArgs e)
{
if (e.RecordLine.Contains(""))
{
string[] parts = SplitStringRespectingEscapeCharacter(eRecordLine);
parts = QuoteAnyPartsWhichContainEscapeCharacter(parts);
parts = RemoveAnyEscapeCharacters(parts);
e.RecordLine = parts.Join;
}
}
You can find some code to get you started on your customized split function here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…