public override bool Resolve (BlockContext ec)
{
expr = expr.Resolve (ec);
if (expr == null)
return false;
if (!TypeManager.IsReferenceType (expr.Type)){
ec.Report.Error (185, loc,
"`{0}' is not a reference type as required by the lock statement",
expr.Type.GetSignatureForError ());
}
if (expr.Type.IsGenericParameter) {
expr = Convert.ImplicitTypeParameterConversion (expr, TypeManager.object_type);
}
VariableReference lv = expr as VariableReference;
bool locked;
if (lv != null) {
locked = lv.IsLockedByStatement;
lv.IsLockedByStatement = true;
} else {
lv = null;
locked = false;
}
ec.StartFlowBranching (this);
Statement.Resolve (ec);
ec.EndFlowBranching ();
if (lv != null) {
lv.IsLockedByStatement = locked;
}
base.Resolve (ec);
//
// Have to keep original lock value around to unlock same location
// in the case the original has changed or is null
//
expr_copy = TemporaryVariableReference.Create (TypeManager.object_type, ec.CurrentBlock.Parent, loc);
expr_copy.Resolve (ec);
//
// Ensure Monitor methods are available
//
if (ResolvePredefinedMethods (ec) > 1) {
lock_taken = TemporaryVariableReference.Create (TypeManager.bool_type, ec.CurrentBlock.Parent, loc);
lock_taken.Resolve (ec);
}
return true;
}