// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Razor.Chunks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Razor.Directives
{
///
/// A that merges instances.
///
public class UsingChunkMerger : IChunkMerger
{
private readonly HashSet _currentUsings = new HashSet(StringComparer.Ordinal);
///
public void VisitChunk([NotNull] Chunk chunk)
{
var namespaceChunk = ChunkHelper.EnsureChunk(chunk);
_currentUsings.Add(namespaceChunk.Namespace);
}
///
public void Merge([NotNull] ChunkTree chunkTree, [NotNull] Chunk chunk)
{
var namespaceChunk = ChunkHelper.EnsureChunk(chunk);
if (!_currentUsings.Contains(namespaceChunk.Namespace))
{
_currentUsings.Add(namespaceChunk.Namespace);
chunkTree.Chunks.Add(namespaceChunk);
}
}
}
}