Hi,
is there way how to get name ov event from Lambda expression like with property ( http://stackoverflow.com/questions/671968/retrieving-property-name-from-lambda-expression ) ?
Thanks
Hi,
is there way how to get name ov event from Lambda expression like with property ( http://stackoverflow.com/questions/671968/retrieving-property-name-from-lambda-expression ) ?
Thanks
No. C# lambdas don't support events, so there is no way of representing this. You'll have to use reflection.
Yes, it's just like getting the property name, but you must do it in the class that defines the event.
public class Foo
{
public event EventHandler Bar;
public string BarName
{
get
{
return this.GetEventName(() => this.Bar);
}
}
private string GetEventName(Expression<Func<EventHandler>> expression)
{
return (expression.Body as MemberExpression).Member.Name;
}
}
Enjoy.