NStub.CSharp.NamespaceDetector.DetermineShortestNamespace C# (CSharp) Method

DetermineShortestNamespace() private static method

Determines the shortest namespace from a list of type declarations.
private static DetermineShortestNamespace ( IEnumerable typeDeclarations, IEnumerable &distinctNamespaces ) : string
typeDeclarations IEnumerable The type declarations.
distinctNamespaces IEnumerable The list of unique namespaces.
return string
        private static string DetermineShortestNamespace(
            IEnumerable<CodeTypeDeclaration> typeDeclarations, out IEnumerable<string> distinctNamespaces)
        {
            var typeNamespace = new List<string>();
            foreach (CodeTypeDeclaration typedecl in typeDeclarations)
            {
                var typeName = typedecl.Name;
                var indexcodeNs = typeName.LastIndexOf('.');
                if (indexcodeNs > 0)
                {
                    var codeNs = typeName.Substring(0, indexcodeNs);
                    typeNamespace.Add(codeNs);
                }
            }

            var typeNamespaceDistinct = typeNamespace.Distinct();
            distinctNamespaces = typeNamespaceDistinct;
            var shortestNamespace = typeNamespaceDistinct.Min();
            return shortestNamespace;
        }