Skip to content
This repository has been archived by the owner on Feb 25, 2021. It is now read-only.

Commit

Permalink
Sanitize base namespace for generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
danroth27 committed Apr 30, 2018
1 parent 4e5e296 commit 9eb6171
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class ComponentDocumentClassifierPass : DocumentClassifierPassBase, IRazo

private static readonly char[] PathSeparators = new char[] { '/', '\\' };

private static readonly char[] NamespaceSeparators = new char[] { '.' };

/// <summary>
/// The base namespace.
/// </summary>
Expand Down Expand Up @@ -141,9 +143,20 @@ private bool TryComputeNamespaceAndClass(string filePath, string relativePath, o
}

var builder = new StringBuilder();
builder.Append(baseNamespace); // Don't sanitize, we expect it to contain dots.

var segments = relativePath.Split(PathSeparators, StringSplitOptions.RemoveEmptyEntries);
// Sanitize the base namespace, but leave the dots.
var segments = baseNamespace.Split(NamespaceSeparators, StringSplitOptions.RemoveEmptyEntries);
builder.Append(CSharpIdentifier.SanitizeClassName(segments[0]));
if (segments.Length > 1)
{
for (var i = 1; i < segments.Length; i++)
{
builder.Append('.');
builder.Append(CSharpIdentifier.SanitizeClassName(segments[i]));
}
}

segments = relativePath.Split(PathSeparators, StringSplitOptions.RemoveEmptyEntries);

// Skip the last segment because it's the FileName.
for (var i = 0; i < segments.Length - 1; i++)
Expand Down

0 comments on commit 9eb6171

Please sign in to comment.