ArchiMetrics.Analysis.Metrics.NamespaceCollector.GetNamespaces C# (CSharp) Method

GetNamespaces() public method

public GetNamespaces ( Microsoft.CodeAnalysis.SyntaxNode commonNode ) : IEnumerable
commonNode Microsoft.CodeAnalysis.SyntaxNode
return IEnumerable
		public IEnumerable<NamespaceDeclarationSyntax> GetNamespaces(SyntaxNode commonNode)
		{
			var node = commonNode as SyntaxNode;
			if (node != null)
			{
				Visit(node);
			}

			return _namespaces.AsArray();
		}

Usage Example

		private static async Task<IEnumerable<NamespaceDeclaration>> GetNamespaceDeclarations(Project project)
		{
			var namespaceDeclarationTasks = project.Documents
				.Select(document => new { document, codeFile = document.FilePath })
				.Where(t => !IsGeneratedCodeFile(t.document, Patterns))
				.Select(
					async t =>
					{
						var collector = new NamespaceCollector();
						var root = await t.document.GetSyntaxRootAsync().ConfigureAwait(false);
						return new
						{
							t.codeFile,
							namespaces = collector.GetNamespaces(root)
						};
					})
				.Select(
					async t =>
					{
						var result = await t.ConfigureAwait(false);
						return result.namespaces
							.Select(
								x => new NamespaceDeclarationSyntaxInfo
								{
									Name = x.GetName(x.SyntaxTree.GetRoot()),
									CodeFile = result.codeFile,
									Syntax = x
								});
					});
			var namespaceDeclarations = await Task.WhenAll(namespaceDeclarationTasks).ConfigureAwait(false);
			return namespaceDeclarations
				.SelectMany(x => x)
				.GroupBy(x => x.Name)
				.Select(y => new NamespaceDeclaration { Name = y.Key, SyntaxNodes = y });
		}