Exemplo n.º 1
0
        public virtual string GetDefaultNamespace(string fileName)
        {
            string relPath = FileUtility.GetRelativePath(this.Directory, Path.GetDirectoryName(fileName));

            string[]      subdirs           = relPath.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
            StringBuilder standardNameSpace = new StringBuilder(this.RootNamespace);

            foreach (string subdir in subdirs)
            {
                if (subdir == "." || subdir == ".." || subdir.Length == 0)
                {
                    continue;
                }
                if (subdir.Equals("src", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (subdir.Equals("source", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (standardNameSpace.Length > 0)
                {
                    standardNameSpace.Append('.');
                }
                standardNameSpace.Append(NewFileDialog.GenerateValidClassOrNamespaceName(subdir, true));
            }
            return(standardNameSpace.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the namespace the file should have in the specified project.
        /// </summary>
        public static string GetDefaultNamespace(IProject project, string fileName)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            string relPath = FileUtility.GetRelativePath(project.Directory, Path.GetDirectoryName(fileName));

            string[]      subdirs           = relPath.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
            StringBuilder standardNameSpace = new StringBuilder(project.RootNamespace);

            foreach (string subdir in subdirs)
            {
                if (subdir == "." || subdir == ".." || subdir.Length == 0)
                {
                    continue;
                }
                if (subdir.Equals("src", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (subdir.Equals("source", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                standardNameSpace.Append('.');
                standardNameSpace.Append(NewFileDialog.GenerateValidClassOrNamespaceName(subdir, true));
            }
            return(standardNameSpace.ToString());
        }