internal static SelectorMatch Evaluate( ILogical logical, IChildIndexProvider childIndexProvider, int step, int offset, bool reversed) { var index = childIndexProvider.GetChildIndex(logical); if (index < 0) { return(SelectorMatch.NeverThisInstance); } if (reversed) { if (childIndexProvider.TryGetTotalCount(out var totalCountValue)) { index = totalCountValue - index; } else { return(SelectorMatch.NeverThisInstance); } } else { // nth child index is 1-based index += 1; } var n = Math.Sign(step); var diff = index - offset; var match = diff == 0 || (Math.Sign(diff) == n && diff % step == 0); return(match ? SelectorMatch.AlwaysThisInstance : SelectorMatch.NeverThisInstance); }
public NthChildActivator( ILogical control, IChildIndexProvider provider, int step, int offset, bool reversed) { _control = control; _provider = provider; _step = step; _offset = offset; _reversed = reversed; }