Vote count:
0
I'm tring to create a methode to response to this case:
this.GetRessource<T>(p => new { "TestConstant", p.Property });
The GetRessource methode must extract the constant value and the property name. I found how to extract the property name, but I not find how to get the constant value.
There is my methode.
public void GetResource<TObject>(Expression<Func<TObject, object>> expression)
{
string constantValue = string.Empty;
string propertyName = string.Empty;
// Get propertyName.
var expressionProperties = expression.Body.Type.GetProperties();
var properties = typeof (TObject).GetProperties()
.Where(pO => lExpressionProperties.Any(pE => pO.Name == pE.Name))
.Select(p => p.Name).ToArray();
propertyName = lProperties[0]; // = Property
// constantValue = ?? ; // must return TestConstant
}
Someone had already be in this situation? or can help me?
Thanks.
asked 4 mins ago
How get a constant value into anonymous type in lambda expression?
Aucun commentaire:
Enregistrer un commentaire