Lambda expressions

From no name for this wiki
Revision as of 22:02, 8 March 2011 by Claude (talk | contribs) (New page: <source lang="csharp"> string GetPropertyName<T>(Expression<Func<T>> property) { var propertyInfo = (property.Body as MemberExpression).Member as PropertyInfo; if (...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
string GetPropertyName<T>(Expression<Func<T>> property)
{
            var propertyInfo = (property.Body as MemberExpression).Member as PropertyInfo;
            if (propertyInfo == null)
            {
                throw new ArgumentException("The lambda expression 'property' should point to a valid Property");
            }
            return propertyInfo.Name;
}

GetPropertyName(() => this.Name);