void OnAssignment(BinaryExpression node)
{
if (NodeType.SlicingExpression == node.Left.NodeType)
{
OnAssignmentToSlice(node);
return;
}
// when the parent is not a statement we need to leave
// the value on the stack
bool leaveValueOnStack = ShouldLeaveValueOnStack(node);
IEntity tag = TypeSystemServices.GetEntity(node.Left);
switch (tag.EntityType)
{
case EntityType.Local:
{
SetLocal(node, (InternalLocal)tag, leaveValueOnStack);
break;
}
case EntityType.Parameter:
{
InternalParameter param = (InternalParameter)tag;
if (param.Parameter.IsByRef)
{
SetByRefParam(param, node.Right, leaveValueOnStack);
break;
}
LoadExpressionWithType(param.Type, node.Right);
if (leaveValueOnStack)
{
Dup();
PushType(param.Type);
}
_il.Emit(OpCodes.Starg, param.Index);
break;
}
case EntityType.Field:
{
IField field = (IField)tag;
SetField(node, field, node.Left, node.Right, leaveValueOnStack);
break;
}
case EntityType.Property:
{
SetProperty((IProperty)tag, node.Left, node.Right, leaveValueOnStack);
break;
}
case EntityType.Event: //event=null (always internal in this context)
{
InternalEvent e = (InternalEvent) tag;
OpCode opcode = e.IsStatic ? OpCodes.Stsfld : OpCodes.Stfld;
_il.Emit(OpCodes.Ldnull);
_il.Emit(opcode, GetFieldBuilder(e.BackingField.Field));
break;
}
default:
{
NotImplemented(node, tag.ToString());
break;
}
}
if (!leaveValueOnStack)
{
PushVoid();
}
}