System.Linq.Expressions.Expression.Property C# (CSharp) Méthode

Property() public static méthode

Creates a MemberExpression accessing a property.
public static Property ( Expression expression, Type type, string propertyName ) : MemberExpression
expression Expression The containing object of the property. This can be null for static properties.
type Type The containing the property.
propertyName string The property to be accessed.
Résultat MemberExpression
        public static MemberExpression Property(Expression expression, Type type, string propertyName)
        {
            ContractUtils.RequiresNotNull(type, nameof(type));
            ContractUtils.RequiresNotNull(propertyName, nameof(propertyName));
            // bind to public names first
            PropertyInfo pi = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.FlattenHierarchy)
                              ?? type.GetProperty(propertyName, BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase | BindingFlags.FlattenHierarchy);
            if (pi == null)
            {
                throw Error.PropertyNotDefinedForType(propertyName, type, nameof(propertyName));
            }
            return Property(expression, pi);
        }

Same methods

Expression::Property ( Expression instance, PropertyInfo indexer ) : IndexExpression
Expression::Property ( Expression instance, PropertyInfo indexer, IEnumerable arguments ) : IndexExpression
Expression::Property ( Expression instance, string propertyName ) : IndexExpression
Expression::Property ( Expression expression, MethodInfo propertyAccessor ) : MemberExpression
Expression::Property ( Expression expression, PropertyInfo property ) : MemberExpression
Expression::Property ( Expression expression, string propertyName ) : MemberExpression

Usage Example

Exemple #1
0
        private static Expression <Func <T, bool> > PrimaryKeyEquals(PropertyInfo property, int value)
        {
            var param = Expression.Parameter(typeof(T));
            var body  = Expression.Equal(Expression.Property(param, property), Expression.Constant(value));

            return(Expression.Lambda <Func <T, bool> >(body, param));
        }
All Usage Examples Of System.Linq.Expressions.Expression::Property
Expression