c# - What's the System.Linq.Expressions.ExpressionVisitor.VisitExtension and the System.Linq.Expressions.ExpressionType.Extension for? -
the system.linq.expressions.expressionvisitor
has method named visitextension
seems nothing other call visitchildren
method on expression
being visited.
protected internal virtual expression visitextension(expression node) { return node.visitchildren(this); }
i understand visitchildren
does. understand virtual implementation can , perhaps meant overriden. gather documentation of method on msdn, sparing in words , briefly remarks:
visits children of extension expression. can overridden visit or rewrite specific extension nodes. if not overridden, method call visitchildren, gives node chance walk children. default, visitchildren try reduce node.
i not find explanation helpful. specifically, phrase jets me out of abilities of comprehension "or rewrite specific extension nodes."
i understand rest of it, pertains reduction or breaking down of expression sub-expressions.
also in same namespace enumeration named expressiontype
, purpose of understand well. of members, there 1 member named extension
cannot map syntactical token aware of.
the documentation in instance, too, frustratingly laconic. describes value extension
follows:
an extension expression.
it obvious 2 -- expressiontype.extension
, expressionvisitor.visitextension
-- related.
but extension? surely, glaringly obvious, extension methods have no place in context. syntactical artifact expression extension refer here?
in case, extension not represent kind of built-in syntax, correspond nodes applications can define , assign arbitrary meaning to.
that concept useful when 1 manipulates expression trees in application, these extension nodes can integrated otherwise normal expression tree.
for example, defined subclass of system.linq.expressions.expression
node type expressiontype.extension
in order extend entity framework's linq understand type of composite primary key in use @ company.
the extension expression type useful because let me use two-step approach:
- in first step, expression visitor regularize every appearance of composite key node of custom type;
- in second step, expression visitor tasked translating expression entity framework able handle check on type;
example: let had linq code written:
from e in table e.firstkey == e.secondkey select e;
where firstkey
, secondkey
both composite database keys (that is, there 2 database columns firstkey1
, firstkey2
firstkey
, , secondkey
).
then first visitor transform both e.firstkey
, e.secondkey
customkeyexpression
nodes, functionally transforming to:
from e in table key(e.firstkey1, e.firstkey2) == key(e.secondkey1, e.secondkey2) select e;
and in second visitor, when visit equalexpression
, check both children customkeyexpression
s, , make appropriate transformation:
from e in table e.firstkey1 == e.secondkey1 && e.firstkey2 == e.secondkey2;
Comments
Post a Comment