// Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.DotNet.ProjectModel.FileSystemGlobbing.Abstractions; namespace Microsoft.DotNet.ProjectModel.FileSystemGlobbing.Internal.PatternContexts { public class PatternContextLinearInclude : PatternContextLinear { public PatternContextLinearInclude(ILinearPattern pattern) : base(pattern) { } public override void Declare(Action onDeclare) { if (IsStackEmpty()) { throw new InvalidOperationException("Can't declare path segment before entering a directory."); } if (Frame.IsNotApplicable) { return; } if (Frame.SegmentIndex < Pattern.Segments.Count) { onDeclare(Pattern.Segments[Frame.SegmentIndex], IsLastSegment()); } } public override bool Test(DirectoryInfoBase directory) { if (IsStackEmpty()) { throw new InvalidOperationException("Can't test directory before entering a directory."); } if (Frame.IsNotApplicable) { return false; } return !IsLastSegment() && TestMatchingSegment(directory.Name); } } }