Created
December 4, 2012 00:27
-
-
Save takeshik/4199355 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static IEnumerable<Expression> TraverseImpl(Expression expression) | |
{ | |
switch (expression.GetType().Name) | |
{ | |
case "BinaryExpression": | |
return (expression as BinaryExpression).Let(e => new [] | |
{ | |
e.Conversion, | |
e.Left, | |
e.Right, | |
}); | |
case "BlockExpression": | |
return (expression as BlockExpression).Let(e => | |
e.Expressions.Concat(e.Variables) | |
); | |
case "ConditionalExpression": | |
return (expression as ConditionalExpression).Let(e => new [] | |
{ | |
e.IfFalse, | |
e.IfTrue, | |
e.Test, | |
}); | |
case "ConstantExpression": | |
return new Expression[0]; | |
case "DebugInfoExpression": | |
return new Expression[0]; | |
case "DefaultExpression": | |
return new Expression[0]; | |
case "DynamicExpression": | |
return (expression as DynamicExpression).Arguments; | |
case "GotoExpression": | |
return new [] | |
{ | |
(expression as GotoExpression).Value, | |
}; | |
case "IndexExpression": | |
return (expression as IndexExpression).Let(e => | |
e.Arguments.EndWith(e.Object) | |
); | |
case "InvocationExpression": | |
return (expression as InvocationExpression).Let( | |
e => e.Arguments.EndWith(e.Expression) | |
); | |
case "LabelExpression": | |
return new[] | |
{ | |
(expression as LabelExpression).DefaultValue, | |
}; | |
case "ListInitExpression": | |
return (expression as ListInitExpression).Let(e => | |
e.Initializers | |
.SelectMany(i => i.Arguments) | |
.EndWith(e.NewExpression) | |
); | |
case "LoopExpression": | |
return new[] | |
{ | |
(expression as LoopExpression).Body, | |
}; | |
case "MemberExpression": | |
return new [] | |
{ | |
(expression as MemberExpression).Expression, | |
}; | |
case "MemberInitExpression": | |
return new[] | |
{ | |
(expression as MemberInitExpression).NewExpression, | |
}; | |
case "MethodCallExpression": | |
return (expression as MethodCallExpression).Let(e => | |
e.Arguments.EndWith(e.Object) | |
); | |
case "NewArrayExpression": | |
return (expression as NewArrayExpression).Expressions; | |
case "NewExpression": | |
return (expression as NewExpression).Arguments; | |
case "ParameterExpression": | |
return new Expression[0]; | |
case "RuntimeVariablesExpression": | |
return (expression as RuntimeVariablesExpression).Variables; | |
case "SwitchExpression": | |
return (expression as SwitchExpression).Let(e => | |
e.Cases | |
.SelectMany(c => c.TestValues.EndWith(c.Body)) | |
.EndWith(e.DefaultBody, e.SwitchValue) | |
); | |
case "TryExpression": | |
return (expression as TryExpression).Let(e => | |
e.Handlers | |
.SelectMany(h => new [] | |
{ | |
h.Body, | |
h.Filter, | |
h.Variable, | |
}) | |
.EndWith(e.Body, e.Fault, e.Finally) | |
); | |
case "TypeBinaryExpression": | |
return new [] | |
{ | |
(expression as TypeBinaryExpression).Expression, | |
}; | |
case "UnaryExpression": | |
return new [] | |
{ | |
(expression as UnaryExpression).Operand, | |
}; | |
case "AmbiguousLambdaExpression": | |
return (expression as AmbiguousLambdaExpression).Let(e => new [] | |
{ | |
e. | |
}); | |
case "AmbiguousParameterExpression": | |
return (expression as AmbiguousParameterExpression).Let(e => new [] | |
{ | |
}); | |
case "ContextfulExpression": | |
return (expression as ContextfulExpression).Let(e => new [] | |
{ | |
}); | |
case "DispatchExpression": | |
return (expression as DispatchExpression).Let(e => new [] | |
{ | |
}); | |
case "IdentifierExpression": | |
return (expression as IdentifierExpression).Let(e => new [] | |
{ | |
}); | |
case "IgnoredExpression": | |
return (expression as IgnoredExpression).Let(e => new [] | |
{ | |
}); | |
case "LambdaListExpression": | |
return (expression as LambdaListExpression).Let(e => new [] | |
{ | |
}); | |
case "ListExpression": | |
return (expression as ListExpression).Let(e => new [] | |
{ | |
}); | |
case "MacroExpression": | |
return (expression as MacroExpression).Let(e => new [] | |
{ | |
}); | |
case "NumberExpression": | |
return (expression as NumberExpression).Let(e => new [] | |
{ | |
}); | |
case "QuotedExpression": | |
return (expression as QuotedExpression).Let(e => new [] | |
{ | |
}); | |
case "SerializedExpression": | |
return (expression as SerializedExpression).Let(e => new [] | |
{ | |
}); | |
case "SymbolTableExpression": | |
return (expression as SymbolTableExpression).Let(e => new [] | |
{ | |
}); | |
case "TextExpression": | |
return (expression as TextExpression).Let(e => new [] | |
{ | |
}); | |
case "TypeCandidateExpression": | |
return (expression as TypeCandidateExpression).Let(e => new [] | |
{ | |
}); | |
case "VectorExpression": | |
return (expression as VectorExpression).Let(e => new [] | |
{ | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment