internal override Expression GetExpression()
{
if (_instance == null)
{
return Expression.Equal(
Expression.Convert(_expression, typeof(object)),
AstUtils.Null
);
}
ParameterExpression temp = Expression.Parameter(typeof(object), null);
return Expression.Block(
new TrueReadOnlyCollection<ParameterExpression>(temp),
new TrueReadOnlyCollection<Expression>(
#if ENABLEDYNAMICPROGRAMMING
Expression.Assign(
temp,
Expression.Property(
Expression.Constant(new WeakReference(_instance)),
typeof(WeakReference).GetProperty("Target")
)
),
#else
Expression.Assign(
temp,
Expression.Constant(_instance, typeof(object))
),
#endif
Expression.AndAlso(
//check that WeakReference was not collected.
Expression.NotEqual(temp, AstUtils.Null),
Expression.Equal(
Expression.Convert(_expression, typeof(object)),
temp
)
)
)
);
}
}