dimanche 1 juin 2014

Write to String using the FixedLengthClassBuilder


Vote count:

0




I have a c# class called "SepaRecord", already defined in a dll which I cannot modify. I have a List at runtime which I need to convert into a fixed length file.


The approach which I have tried is, using the FixedLengthClassBuilder I create a runtime definition of the record, as below:



FixedLengthClassBuilder fileRecordBuilder = new FixedLengthClassBuilder("SepaRecord");
fileRecordBuilder.AddField("RecordCode", 2, typeof(string));
fileRecordBuilder.AddField("CurrencyCode", 3, typeof(string));
fileRecordBuilder.AddField("CreditAmount", 15, typeof(int));
// other fields follow....


RecordCode, CurrencyCode, CreditAmount, etc are fields defined the "SepaRecord" class in the DLL.


I would expect that if I pass the list to the FileHelperEngine, I would get back a delimited string:



List<SepaRecord> lst = this.goGetMyList();
string ret = this.FileHelperEngine.WriteString(lst);


But of course it did not work since the FixedLengthClassBuilder builts and compiles a type/class at runtime and compares it with the class/type of the argument.


Question is: Is there a better approach to do what I am trying to do?

And a suggestion: Why bother with type checks? Just compare on the field level. I think this would make the runtime engine more flexible.


Appreciate any help Chris



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire