public static string GetDefaultNamespace(AIMS.Libraries.Scripting.ScriptControl.Project.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(project.Directory + 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()); }
private string GetInitialContents(NewFileDialog f, string fileName) { string defNameSpace = NewFileDialog.GetDefaultNamespace(m_AIMSProject, fileName); string defClassName = NewFileDialog.GenerateValidClassOrNamespaceName(Path.GetFileNameWithoutExtension(fileName), true); StringBuilder contents = new StringBuilder(); if (_scriptLanguage == ScriptLanguage.CSharp) { contents.AppendLine("#region Usings ..."); contents.AppendLine("using System;"); contents.AppendLine("using System.Collections.Generic;"); contents.AppendLine("using System.Text;"); contents.AppendLine("#endregion"); contents.AppendLine(""); contents.AppendLine("namespace " + defNameSpace); contents.AppendLine("{"); contents.AppendLine(" " + (f.SelectedItemType == SelectedItemType.Class ? "class " : "interface ") + defClassName); contents.AppendLine(" {"); contents.AppendLine(""); contents.AppendLine(" }"); contents.AppendLine("}"); } else { contents.AppendLine("#Region Usings ..."); contents.AppendLine("Imports System"); contents.AppendLine("Imports System.Collections.Generic"); contents.AppendLine("Imports System.Text"); contents.AppendLine("#End Region"); contents.AppendLine(""); contents.AppendLine("Namespace " + defNameSpace); contents.AppendLine(" " + (f.SelectedItemType == SelectedItemType.Class ? "Class " : "Interface ") + defClassName); contents.AppendLine(""); contents.AppendLine(" End " + (f.SelectedItemType == SelectedItemType.Class ? "Class" : "Interface")); contents.AppendLine("End Namespace"); } return(contents.ToString()); }