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;
}