XmlSchemaClassGenerator icon indicating copy to clipboard operation
XmlSchemaClassGenerator copied to clipboard

Add the possibility to specify an output filename

Open SierraNL opened this issue 7 years ago • 3 comments

It would be handy to specify the output filename, currently it's only possible to select the output folder. (I guess since you can have more then 1 file). But when you do have one file, it would be great if you could specify it.

This is meant for the console version and the dotnettool version.

SierraNL avatar Jun 26 '18 13:06 SierraNL

Currently, the file names are identical to the C# namespace names (plus ".cs"). So one way of specifying the file name is to set the C# namespace name. It would be a nice feature to be able to specify the file name independently of the namespace. This could be added to the -n option, e.g.

-n XmlNamespace|a.xsd=CSNamespace|Filename.cs

mganss avatar Jun 28 '18 12:06 mganss

I was badly in need of this feature, so implemented my own File writer to achieve it.

public class SingleFileOutputWriter : FileOutputWriter
    {
        public SingleFileOutputWriter(string directory, bool createIfNotExists = true)
         : base(directory, createIfNotExists)
        {
        }

        public string OutputFile { get; set; }

        public override void Write(CodeNamespace cn)
        {
            var cu = new CodeCompileUnit();
            cu.Namespaces.Add(cn);

            if (string.IsNullOrWhiteSpace(OutputFile))
            {
                OutputFile = $"{cn.Name}.cs";
            }

            WriteFile(Path.Combine(OutputDirectory, OutputFile), cu);
        }
    }

rashan avatar Feb 13 '19 09:02 rashan

@rashan ; Can you maybe create a PR for this?

StefH avatar Sep 06 '19 06:09 StefH