I'm using an in-house file parsing library, which I'm using to parse a gnarly reporting file generated by a legacy system. The library iterates allows you to define Linq queries which are applied successively to return an enumerable set of structures in the file.
A typical example would be something like the below.
var OrderReportParser =
from blanks in Rep(BlankLine) // One or more blank lines
from header1 in TextLine // A header text line with no useful information
from hyphenLine in WhiteSpace.And(Rep(Char('-'))).And(BlankLine)
// A line containing only hyphens
/* ... Snip ... lots of other from clauses */
from orderId in WhiteSpace.And(AlphaNumeric) // The id of this record
from price in WhiteSpace.And(Decimal) // Order price
from quantity in WhiteSpace.And(Integer) // Order quantity
select new OrderLine (orderId, price, quantity)
Because much of my file is simply text, many of the intermediate results generated by a statement such as the above are not required in the output (such as the variables blanks
, header1
, hyphenLine
in the example above).
Is there any such mechanism in C# creating variables for the intermediate results, or do I always to create variable for each?
I am thinking of examples such as F#'s _
variable, which can be used in this fashion. See F#'s underscore: why not just create a variable name? for an example in the context of Tuples.