I'm looking to get a value from an
Expression<Func<Someobject, bool>> selector = x => x.SomeId == "SOMEGUID-GUID-GUID-GUID-SOMEGUIDGUID";
For logging purposes I need to be able to fish out that guid.
I tried the following code, which I feel is somewhat close to what I'm looking for, but not quite.
BinaryExpression binaryExpression = (BinaryExpression)selector.Body;
MemberExpression memberExpression = (MemberExpression)((UnaryExpression)binaryExpression.Right).Operand;
ConstantExpression constantExpression = (ConstantExpression)memberExpression.Expression;
Now, ConstantExpression exposes a member 'Value', which does contain what I'm looking for, but I'm a bit puzzled how to actually extract this.
And no:
var val = (Guid)constantExpression.Value;
Does not work :)
Aucun commentaire:
Enregistrer un commentaire