I built my own SQL Query constructor that breaks the expression, however, I am having trouble trying to get the value of a string defined in the same function as the lambda expression.
Here is what I am trying to do in a console application:
private static void MyBuilderTest() { var sqlBuilder = new SqlBuilder();
In my builder, these are subclasses from ExpressionVisitor, and I override VisitMember. I found that a line defined at the base level of the console will return as:
Node.Expression.NodeType == ExpressionType.Constant
Node.Expression returns the properties:
CanReduce = false DebugView = ".Constant<ConsoleApplication1.Program+<>c__DisplayClass1>(ConsoleApplication1.Program+<>c__DisplayClass1)" NodeType = Constant Type = System.Type {System.RunetimeType} Value = {ConsoleApplication1.Program}
Node.Expression.Value contains:
testValue = "Test" (Type: string)
How do I get this value? I tried several things, for example:
var memberType = node.Expression.Type.DeclaringType;
This returns the type ConsoleApplication1.Program.
However, when I do this:
memberType.GetProperty("testValue"); // Declaring Type from Expression
It returns null.
The above methods work fine if I put lambda strings in a class, but don't work if they are defined in the console function.
Can someone tell me how to get a string value if it is defined at the level of the lambda function?
EDITED: Added by VisitMember
protected override Expression VisitMember(MemberExpression node) { if (node.NodeType == ExpressionType.Constant) {
EDITED
Added code to the console application example to show what works and what doesn't.