/// <summary> /// Returns the property that is being referenced by the specified expression. /// </summary> /// <typeparam name="TParent">The type of the parent.</typeparam> /// <typeparam name="TProperty">The type of the property.</typeparam> /// <param name="expression">The expression.</param> /// <returns></returns> public static PropertyInfo AsProperty <TParent, TProperty>(this Expression <Func <TParent, TProperty> > expression) { var visitor = new AsMemberExpressionVisitor <PropertyInfo>(); visitor.Visit(expression); return(visitor.Member); }
/// <summary> /// Returns the field that is being referenced by the specified expression. /// </summary> /// <typeparam name="TParent">The type of the parent.</typeparam> /// <typeparam name="TField">The type of the field.</typeparam> /// <param name="expression">The expression.</param> /// <returns></returns> public static FieldInfo AsField <TParent, TField>(this Expression <Func <TParent, TField> > expression) { var visitor = new AsMemberExpressionVisitor <FieldInfo>(); visitor.Visit(expression); return(visitor.Member); }