public bool Select <TSelect>(Action <MemoryNode <TSelect> > callback) where TSelect : class { if (typeof(TSelect) == typeof(T) && _node == null) { _left.Match <T, TDiscard>(n => _node = n); } var node = _node as MemoryNode <TSelect>; if (node != null) { callback(node); return(true); } if (_parent == null) { if (!typeof(T).IsGenericType || typeof(T).GetGenericTypeDefinition() != typeof(Token <,>)) { return(false); } Type[] arguments = typeof(T).GetGenericArguments(); _parent = (RuleNodeSelector)Activator.CreateInstance( typeof(DiscardRuleNodeSelector <,>).MakeGenericType(arguments), _configurator, this); } return(_parent.Select(callback)); }
public void Select <TNode>(MemoryNode <TNode> node) where TNode : class { var alphaNode = node as AlphaNode <T>; if (alphaNode == null) { throw new ArgumentException("Only alpha nodes can be condition alpha nodes"); } var conditionAlphaNode = new RuleNodeSelector <T>(_configurator, alphaNode); _nodeCallback(conditionAlphaNode); }