1

It's probably best I explain with an example.

I am writing a fluent interface, which includes a Where method:

public FluentSearch Where(Expression<Func<IJourney, bool>> expression)

which I might call like this:

.Where(j => j.Driver.Chatiness == searchResource.Chatiness)

Using a watch in the debugger, I can see that there is a property with the value I'm after:

expression.Expression.Member.Name

However, when I create a watch from this property, I get the following:

((new System.Linq.Expressions.Expression.MemberExpressionProxy((new System.Linq.Expressions.Expression.MemberExpressionProxy(expression as System.Linq.Expressions.PropertyExpression)).Expression as System.Linq.Expressions.PropertyExpression)).Member).Name

However the compiler complains about the protection level of the MemberExpressionProxy, as well as a complaint about the number of arguments to a constructor.

Does anyone know how I can get around this problem and get either a name in a string, or a type (IDriver in this case)?

svick
  • 236,525
  • 50
  • 385
  • 514
serlingpa
  • 12,024
  • 24
  • 80
  • 130
  • 1
    What do you mean by "strong name"? What exactly is the value you are after? – Jon May 20 '14 at 11:16
  • Ok strong name was a bit woolly. Ideally I'd like to return the type (IDriver in this case), but a string "Driver" will do. – serlingpa May 20 '14 at 11:22
  • `.Where(j => someUnrelatedVariable.Answer == 42)` -- what now? `.Where(j => randomValue() > 0.5)` -- what now? `.Where(j => count++ % 2 == 1)` -- etc etc. – Jon May 20 '14 at 11:24
  • I'm soryy Jon I don't know what you're asking me. – serlingpa May 20 '14 at 11:26
  • I 'm saying that in this specific example, I can understand how the correct answer `IDriver` or `Driver` might be reached. But `expression` can be *anything*. It might involve a property access to something other than `j`, or no property access at all, or two accesses on different objects, or anything. What should happen then? – Jon May 20 '14 at 11:27
  • The queries will be limited to constants (.Where(j=>j.Test == "SomeConstant")), or expressions to be compiled (.Where(j=>j.Test == SomeExpressionToBeCompile)), or referencing the only enclosed object in the journey, that is the driver (.Where(j=>j.Test == j.Driver.SomeProperty)) – serlingpa May 20 '14 at 11:41
  • Sorry for pestering you, especially since I am not going to attempt to answer (question not adequately specified), but what about `.Where(j => j.Foo == "Foo" || j.Bar == "Bar")`? Examples are good *in addition to* a proper statement of intent, but on their own not so much. Even your own last example leaves open the question "well, do you want to get the type of `Test` or the type of `Driver` back?" – Jon May 20 '14 at 11:44
  • The code to extract the name is being used in a if (expression is MemberExpression) block so it will only attempt to find a name if there is one available. – serlingpa May 20 '14 at 11:49

0 Answers0