This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GetUnitByNameVisitor : IVisitor | |
{ | |
//The parameter | |
private string _unitName; | |
//The return value | |
public Unit ReturnedUnit { get; private set; } | |
public GetUnitByNameVisitor(string unitName) | |
{ | |
_unitName = unitName; | |
} | |
public void VisitProcessUnit(ProcessUnit unit) | |
{ | |
//Accessing the parameter using the private field. | |
if (unit.Name == _unitName) | |
{ | |
//If this process unit is the one we are looking for | |
//return, since there is no need to search in other children | |
ReturnedUnit = unit; | |
return; | |
} | |
foreach (var childUnit in unit.ChildUnits) | |
{ | |
childUnit.AcceptVisitor(this); | |
//If the unit has been found in this child, return, | |
//since there is no need to search in the other siblings. | |
if (ReturnedUnit != null) | |
return; | |
} | |
} | |
public void VisitAgentUnit(AgentUnit unit) | |
{ | |
//Accessing the parameter using the private field | |
if (unit.Name == _unitName) | |
ReturnedUnit = unit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment