private Expression ByValParameterTypeEqual(ParameterExpression value)
{
Expression getType = Expression.Call(value, Object_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)
{
ParameterExpression temp = Expression.Parameter(typeof(Type));
getType = Expression.Block(
new TrueReadOnlyCollection<ParameterExpression>(temp),
new TrueReadOnlyCollection<Expression>(
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, Utils.Null),
Expression.ReferenceEqual(
getType,
Expression.Constant(TypeOperand.GetNonNullableType(), typeof(Type))
)
);
}