Dynamic Linq Library to generate particular type object for selected properties -
im using dynamic linq library application, in sample of dynamic linq library, can pass string of comma separated columns name or property names select clause of linq below .select("new (accountingdocumentnbr,documentfiscalyearnbr)");
can pass object instantiate , populate property values object below
.select("new accountingobject(accountingdocumentnbr,documentfiscalyearnbr)");
accountingobject have accountingdocumentnbr,documentfiscalyearnbr. possible dynamic linq library . http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx
need inputs on this..
well, in theory code should looks this:
function parsenew() expression nexttoken() validatetoken(tokenid.openparen, res.openparenexpected) nexttoken() dim properties new list(of dynamicproperty)() dim expressions new list(of expression)() dim exprpos = tokenval.pos dim expr = parseexpression() dim propname string if tokenidentifieris("as") nexttoken() propname = getidentifier() nexttoken() else dim [me] memberexpression = trycast(expr, memberexpression) if [me] nothing throw parseerror(exprpos, res.missingasclause) propname = [me].member.name end if expressions.add(expr) properties.add(new dynamicproperty(propname, expr.type)) if tokenval.id <> tokenid.comma exit nexttoken() loop validatetoken(tokenid.closeparen, res.closeparenorcommaexpected) nexttoken() dim type type = if(newresulttype, dynamicexpression.createclass(properties)) dim bindings(properties.count - 1) memberbinding integer = 0 bindings.length - 1 bindings(i) = expression.bind(type.getproperty(properties(i).name), expressions(i)) next return expression.memberinit(expression.[new](type), bindings) end function
but how calling select method? should looks more or less this:
.select<objectholder>("new (activity activity, activityname activityname)")
Comments
Post a Comment