Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Fixed custom tool output namespace for VB projects (http://community.…
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrunwald committed Sep 28, 2010
1 parent 748caff commit dc35d18
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
Expand Up @@ -56,13 +56,22 @@ public void GenerateCode(FileProjectItem item, CustomToolContext context)

string[] unmatchable = null;

string generatedCodeNamespace = context.OutputNamespace;
if (context.Project.LanguageProperties == ICSharpCode.SharpDevelop.Dom.LanguageProperties.VBNet) {
if (generatedCodeNamespace == context.Project.RootNamespace) {
generatedCodeNamespace = null; // namespace is implicit in VB
} else if (generatedCodeNamespace.StartsWith(context.Project.RootNamespace + ".", StringComparison.OrdinalIgnoreCase)) {
generatedCodeNamespace = generatedCodeNamespace.Substring(context.Project.RootNamespace.Length + 1);
}
}

context.WriteCodeDomToFile(
item,
context.GetOutputFileName(item, ".Designer"),
StronglyTypedResourceBuilder.Create(
resources, // resourceList
Path.GetFileNameWithoutExtension(inputFilePath), // baseName
context.OutputNamespace, // generatedCodeNamespace
generatedCodeNamespace, // generatedCodeNamespace
context.OutputNamespace, // resourcesNamespace
context.Project.LanguageProperties.CodeDomProvider, // codeProvider
createInternalClass, // internal class
Expand Down
Expand Up @@ -331,6 +331,7 @@ public override object VisitMethodDeclaration(MethodDeclaration methodDeclaratio
CodeMemberMethod memberMethod = new CodeMemberMethod();
memberMethod.Name = methodDeclaration.Name;
memberMethod.Attributes = ConvMemberAttributes(methodDeclaration.Modifier);
memberMethod.ReturnType = ConvType(methodDeclaration.TypeReference);

// RG: Private Interface Decl
if ((memberMethod.Attributes & MemberAttributes.Public) != MemberAttributes.Public &&
Expand Down
37 changes: 19 additions & 18 deletions src/Main/Base/Project/Src/Project/CustomTool.cs
Expand Up @@ -32,7 +32,6 @@ public sealed class CustomToolContext
{
IProject project;
IProgressMonitor progressMonitor;
string outputNamespace;
internal bool RunningSeparateThread;

public CustomToolContext(IProject project)
Expand All @@ -56,10 +55,7 @@ public CustomToolContext(IProject project, IProgressMonitor progressMonitor)
get { return project; }
}

public string OutputNamespace {
get { return outputNamespace; }
set { outputNamespace = value; }
}
public string OutputNamespace { get; set; }

/// <summary>
/// Runs a method asynchronously. Prevents another CustomTool invocation
Expand Down Expand Up @@ -419,20 +415,25 @@ public static string GetDefaultNamespace(IProject project, string fileName)
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));
if (project.LanguageProperties == Dom.LanguageProperties.VBNet) {
return project.RootNamespace;
} else {
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;
if (standardNameSpace.Length > 0)
standardNameSpace.Append('.');
standardNameSpace.Append(NewFileDialog.GenerateValidClassOrNamespaceName(subdir, true));
}
return standardNameSpace.ToString();
}
return standardNameSpace.ToString();
}

static void RunCustomTool(CustomToolRun run)
Expand Down

0 comments on commit dc35d18

Please sign in to comment.