// Helper that is used when re-eval of LHS is safe.
private Expression ByValParameterTypeEqual(ParameterExpression value)
{
Expression getType = Expression.Call(value, typeof(object).GetMethod("GetType"));
// In remoting scenarios, obj.GetType() can return an interface.
// But JIT32's optimized "obj.GetType() == typeof(ISomething)" codegen,
// causing it to always return false.
// We workaround this optimization by generating different, less optimal IL
// if TypeOperand is an interface.
if (_typeOperand.GetTypeInfo().IsInterface)
{
var temp = Expression.Parameter(typeof(Type));
getType = Expression.Block(new[] { temp }, Expression.Assign(temp, getType), temp);
}
// We use reference equality when comparing to null for correctness
// (don't invoke a user defined operator), and reference equality
// on types for performance (so the JIT can optimize the IL).
return(Expression.AndAlso(
Expression.ReferenceNotEqual(value, Expression.Constant(null)),
Expression.ReferenceEqual(
getType,
Expression.Constant(_typeOperand.GetNonNullableType(), typeof(Type))
)
));
}