private Func<BehaviorChain> find(ChainSearch search)
{
var candidates = search.FindCandidates(_behaviorGraph);
var count = candidates.Count();
switch (count)
{
case 1:
var chain = candidates.Single();
return () => chain;
case 0:
return () =>
{
if (!search.Required)
{
return null;
}
throw new FubuException(2104, "No behavior chains are registered matching criteria: " + search);
};
default:
var message = "More than one behavior chain matching criteria: " + search;
message += "\nMatches:";
candidates.Each(x =>
{
message += "\n" + x;
});
return () =>
{
throw new FubuException(2108, message);
};
}
}