Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to prevent Prefix being added to output path #301

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions XmlSchemaClassGenerator.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static void Main(string[] args)
var createGeneratedCodeAttributeVersion = true;
var netCoreSpecificCode = false;
var generateCommandLineArgs = true;
var addPrefixToOutputPath = true;

var options = new OptionSet {
{ "h|help", "show this message and exit", v => showHelp = v != null },
Expand Down Expand Up @@ -87,6 +88,7 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l
{ "r|order", "emit order for all class members stored as XML element", v => emitOrder = v != null },
{ "c|pcl", "PCL compatible output", v => pclCompatible = v != null },
{ "p|prefix=", "the {PREFIX} to prepend to auto-generated namespace names", v => namespacePrefix = v },
{ "po|prefixOnOutput", "include the prefix on the path (default is enabled)", v => addPrefixToOutputPath = v != null },
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the phrasing can be improved here. Perhaps: "po|prefixPath", "include namespace prefix in output paths (default is enabled)"

{ "v|verbose", "print generated file names on stdout", v => verbose = v != null },
{ "0|nullable", "generate nullable adapter properties for optional elements/attributes w/o default values", v => nullables = v != null },
{ "f|ef", "generate Entity Framework Code First compatible classes", v => entityFramework = v != null },
Expand Down Expand Up @@ -204,6 +206,8 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l
CreateGeneratedCodeAttributeVersion = createGeneratedCodeAttributeVersion,
NetCoreSpecificCode = netCoreSpecificCode,
GenerateCommandLineArgumentsComment = generateCommandLineArgs,
NamespacePrefix = namespacePrefix,
AddPrefixToOutputPath = addPrefixToOutputPath,
};

generator.CommentLanguages.AddRange(commentLanguages);
Expand Down
16 changes: 14 additions & 2 deletions XmlSchemaClassGenerator/FileOutputWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ public override void Write(CodeNamespace cn)
}
else
{
var path = Path.Combine(OutputDirectory, cn.Name + ".cs");
var fileName = cn.Name;
if (Configuration != null && !Configuration.AddPrefixToOutputPath && !string.IsNullOrEmpty(Configuration.NamespacePrefix))
{
fileName = cn.Name.Replace($"{Configuration.NamespacePrefix}.", string.Empty);
}

var path = Path.Combine(OutputDirectory, fileName + ".cs");
Configuration?.WriteLog(path);
WriteFile(path, cu);
}
Expand Down Expand Up @@ -68,7 +74,13 @@ protected virtual void WriteFile(string path, CodeCompileUnit cu)

private void WriteSeparateFiles(CodeNamespace cn)
{
var dirPath = Path.Combine(OutputDirectory, ValidateName(cn.Name));
var dirName = cn.Name;
if (Configuration != null && !Configuration.AddPrefixToOutputPath && !string.IsNullOrEmpty(Configuration.NamespacePrefix))
{
dirName = cn.Name.Replace($"{Configuration.NamespacePrefix}.", string.Empty);
}

var dirPath = Path.Combine(OutputDirectory, ValidateName(dirName));
var ccu = new CodeCompileUnit();
var cns = new CodeNamespace(ValidateName(cn.Name));

Expand Down
6 changes: 6 additions & 0 deletions XmlSchemaClassGenerator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ public CommandLineArgumentsProvider CommandLineArgumentsProvider
set { _configuration.CommandLineArgumentsProvider = value; }
}

public bool AddPrefixToOutputPath
{
get { return _configuration.AddPrefixToOutputPath; }
set { _configuration.AddPrefixToOutputPath = value; }
}

static Generator()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Expand Down
7 changes: 7 additions & 0 deletions XmlSchemaClassGenerator/GeneratorConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public GeneratorConfiguration()
Version = VersionProvider.CreateFromAssembly();
EnableUpaCheck = true;
CommandLineArgumentsProvider = CommandLineArgumentsProvider.CreateFromEnvironment();
AddPrefixToOutputPath = true;
}

/// <summary>
Expand Down Expand Up @@ -316,5 +317,11 @@ public void WriteLog(string message)
/// A provider to obtain the command line arguments of the tool.
/// </summary>
public CommandLineArgumentsProvider CommandLineArgumentsProvider { get; set; }

/// <summary>
/// Adds the Namespace prefix to the Output path
/// Default is true.
/// </summary>
public bool AddPrefixToOutputPath { get; set; }
}
}