System.Dynamic.BindingRestrictions.GetExpressionRestriction C# (CSharp) Method

GetExpressionRestriction() public static method

Creates the binding restriction that checks the expression for arbitrary immutable properties.
By convention, the general restrictions created by this method must only test immutable object properties.
public static GetExpressionRestriction ( Expression expression ) : BindingRestrictions
expression System.Linq.Expressions.Expression The expression expressing the restrictions.
return BindingRestrictions
        public static BindingRestrictions GetExpressionRestriction(Expression expression)
        {
            ContractUtils.RequiresNotNull(expression, nameof(expression));
            ContractUtils.Requires(expression.Type == typeof(bool), nameof(expression));
            return new CustomRestriction(expression);
        }

Usage Example

    private static BindingRestrictions AddRemoteObjectRestrictions(BindingRestrictions restrictions, object[] args, ReadOnlyCollection<ParameterExpression> parameters)
    {
#if !SILVERLIGHT

        for (int i = 0; i < parameters.Count; i++)
        {
            var expr = parameters[i];
            var value = args[i] as MarshalByRefObject;

            // special case for MBR objects.
            // when MBR objects are remoted they can have different conversion behavior
            // so bindings created for local and remote objects should not be mixed.
            if (value != null && !IsComObject(value))
            {
                BindingRestrictions remotedRestriction;
                if (RemotingServices.IsObjectOutOfAppDomain(value))
                {
                    remotedRestriction = BindingRestrictions.GetExpressionRestriction(
                                             Expression.AndAlso(
                                                 Expression.NotEqual(expr, Expression.Constant(null)),
                                                 Expression.Call(
                                                     typeof(RemotingServices).GetMethod("IsObjectOutOfAppDomain"),
                                                     expr
                                                 )
                                             )
                                         );
                }
                else
                {
                    remotedRestriction = BindingRestrictions.GetExpressionRestriction(
                                             Expression.AndAlso(
                                                 Expression.NotEqual(expr, Expression.Constant(null)),
                                                 Expression.Not(
                                                     Expression.Call(
                                                         typeof(RemotingServices).GetMethod("IsObjectOutOfAppDomain"),
                                                         expr
                                                     )
                                                 )
                                             )
                                         );
                }
                restrictions = restrictions.Merge(remotedRestriction);
            }
        }

#endif
        return restrictions;
    }
All Usage Examples Of System.Dynamic.BindingRestrictions::GetExpressionRestriction