c# - FileHelper can't handle ReSharper sorting variables in its classes -


i have code doing this:

var engine = new filehelperengine<sampletype>(); var records = engine.readstring("asdf|fdsa");  var showstring = records[0].field1 + records[0].field2; 

the sampletype class looks this:

[delimitedrecord("|")] public class sampletype {     public string field2;     public string field1; } 

the resultset follows:

records[0].field1 has value fdsa

records[0].field2 has value asdf

if run resharper cleanup sort variables alphabetically. , sampletype class this:

[delimitedrecord("|")] public class sampletype {     public string field1;     public string field2; } 

but logic of program has changed.

records[0].field1 has value asdf

records[0].field2 has value fdsa

is there way tell classes order of defined variables irrelevant? defining order of variables relevant, contrary other class have ever seen, find disturbing , strange.

i'm not sure, think want way make filehelpers use explicitly-specified ordering fields, rather implicit 'the order defined in in source'.

if i'm right, want the fieldorder attribute filehelpers library:

force field order [fieldorder] attribute:

//-> first declare record mapping class: input.txt  10248|vinet|04071996|32.38 10249|tomsp|05071996|11.61 10250|hanas|08071996|65.83 10251|victe|08071996|41.34   recordclass.cs  [delimitedrecord("|")] public class orders {     [fieldorder(20)]     public string customerid;      [fieldconverter(converterkind.date, "ddmmyyyy")]     [fieldorder(30)]     public datetime orderdate;      [fieldconverter(converterkind.decimal, ".")] // decimal separator "."     [fieldorder(40)]     public decimal freight;      [fieldorder(10)]     public int orderid; } 

as comment

however quite surprised of how ok way of solving problem in such library seems you. , record, not logical, , able understand it, you'll have "overthink" :p it's not part of languages design

you're right in default operation mode of filehelper here (to use source-ordering of fields in-record ordering) isn't 'native' c#, , indeed isn't particularly 'c#-ish' way of doing things; that's ok if it's how authors , users of filehelpers want it. have flavour of more dynamic-language style, that's a bit how c# headed anyway...


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -