public void Process(Instruction instruction)
{
Command command;
switch (instruction.InstructionType)
{
case InstructionType.NamespaceDeclaration:
command = new NamespaceDeclarationCommand(instruction.NamespaceDeclaration, StateCommuter);
break;
case InstructionType.StartObject:
command = new StartObjectCommand(StateCommuter, TypeSource, instruction.XamlType, rootInstance);
break;
case InstructionType.StartMember:
command = new StartMemberCommand(StateCommuter, GetActualMemberFromMemberSpecifiedInInstruction(instruction.Member));
break;
case InstructionType.Value:
command = new ValueCommand(StateCommuter, valueContext, (string) instruction.Value);
break;
case InstructionType.EndObject:
command = new EndObjectCommand(StateCommuter, stateCommuter => Result = stateCommuter.Current.Instance, LifecycleListener);
break;
case InstructionType.EndMember:
command = new EndMemberCommand(TypeSource, StateCommuter, valueContext);
break;
case InstructionType.GetObject:
command = new GetObjectCommand(StateCommuter);
break;
default:
throw new ParseException($"The XamlInstructionType {instruction.InstructionType} has an unexpected value");
}
command.Execute();
}