" /e /element:NAME Element from schema to generate code for.\n" +\r
" Multiple elements can be specified.\n" +\r
" /u /uri:NAME Namespace uri of the elements to generate code for.\n" +\r
- " /l /language:NAME The language to use for the generated code.\n" +\r
- " Currently, the only supported language is CS (C#).\n" +\r
- " /g /generator:NAME[,FILE] Code Generator type name, optionally followed by ',' assembly file name.\n" +\r
+ " /l /language:NAME The language, or type name of custom CodeDomProvider\n" +\r
+ " to use for the generated code.\n" +\r
+ " Shorthand specifiers are: \"CS\" (C#) and \"VB\" (VB.NET).\n" +\r
+ " For type name, assembly qualified name is required.\n" +\r
+ " /g /generator:TYPE Code Generator type name, followed by ','\n" + \r
+ " and assembly file name.\n" +\r
" /o /outputdir:PATH The directory where to generate the code or schemas.\n" +\r
" /n /namespace:NAME Namespace for the generated code.\n" +\r
" /t /type:NAME Type for which to generate an xml schema.\n" +\r
{\r
new Driver().Run (args);\r
}\r
- catch (Exception ex)\r
+ catch (ApplicationException ex)\r
{\r
Console.WriteLine (ex.Message);\r
+ }\r
+ catch (Exception ex)\r
+ {\r
Console.WriteLine (ex);\r
}\r
}\r
\r
foreach (string arg in args)\r
{\r
- if (!arg.StartsWith ("--") && !arg.StartsWith ("/")) {\r
- if (arg.EndsWith (".dll") || arg.EndsWith (".exe"))\r
+ if (!arg.StartsWith ("--") && !arg.StartsWith ("/") ||\r
+ (arg.StartsWith ("/") && arg.IndexOfAny (Path.InvalidPathChars) == -1)\r
+ ) \r
+ {\r
+ if ((arg.EndsWith (".dll") || arg.EndsWith (".exe")) && !arg.Substring (1).StartsWith ("generator:") && !arg.Substring (1).StartsWith ("g:"))\r
{\r
- if (!readingFiles) throw new Exception (incorrectOrder);\r
+ if (!readingFiles) throw new ApplicationException (incorrectOrder);\r
assemblies.Add (arg);\r
assemblyOptions = true;\r
continue;\r
inference = true;\r
continue;\r
}\r
- else //if (!arg.StartsWith ("/") && !arg.StartsWith ("-"))\r
+ else if (!arg.StartsWith ("/"))\r
{\r
if (!readingFiles) Error (incorrectOrder);\r
unknownFiles.Add (arg);\r
\r
if (outputDir == null) outputDir = ".";\r
\r
+ string typename = null;\r
+ Type generatorType = null;\r
+\r
if (language != null) {\r
switch (language) {\r
case "CS":\r
provider = new VBCodeProvider ();\r
break;\r
default:\r
- Error (languageNotSupported, language);\r
+ typename = StripQuot (language);\r
+\r
+ generatorType = Type.GetType (typename);\r
+ if (generatorType == null)\r
+ Error (generatorTypeNotFound, typename);\r
break;\r
}\r
}\r
\r
if (providerOption != null) {\r
string param = providerOption;\r
- string typename;\r
- Type generatorType;\r
int comma = param.IndexOf (',');\r
if (comma < 0) {\r
- typename = param;\r
+ typename = StripQuot (param);\r
generatorType = Type.GetType (param);\r
} else {\r
typename = param.Substring (0, comma);\r
}\r
if (generatorType == null)\r
Error (generatorTypeNotFound, typename);\r
+ }\r
+ if (generatorType != null) {\r
if (!generatorType.IsSubclassOf (typeof (CodeDomProvider)))\r
Error (generatorTypeIsNotCodeGenerator, typename);\r
try {\r
provider = (CodeDomProvider) Activator.CreateInstance (generatorType, null);\r
} catch (Exception ex) {\r
- Error (generatorThrewException, param);\r
+ Error (generatorThrewException, generatorType.AssemblyQualifiedName.ToString () + " --> " + ex.Message);\r
}\r
- Console.WriteLine ("Loaded custom generator type " + param + " .");\r
+ Console.WriteLine ("Loaded custom generator type " + generatorType + " .");\r
}\r
+ if (provider == null)\r
+ provider = new CSharpCodeProvider ();\r
\r
if (schemasOptions)\r
{\r
else if (inference)\r
{\r
foreach (string xmlfile in inferenceNames) {\r
- string genFile = Path.Combine (outputDir, Path.ChangeExtension (xmlfile, ".xsd"));\r
+ string genFile = Path.Combine (outputDir, Path.GetFileNameWithoutExtension (xmlfile) + ".xsd");\r
DataSet ds = new DataSet ();\r
ds.InferXmlSchema (xmlfile, null);\r
ds.WriteXmlSchema (genFile);\r
\r
// Generate the code\r
\r
- CodeDomProvider p = provider != null ? provider : new CSharpCodeProvider ();\r
- ICodeGenerator gen = p.CreateGenerator();\r
+ ICodeGenerator gen = provider.CreateGenerator();\r
\r
string genFile = Path.Combine (outputDir, targetFile);\r
StreamWriter sw = new StreamWriter(genFile, false);\r
\r
public void GenerateDataset ()\r
{\r
- if (namesp == null) namesp = "Schemas";\r
+ if (namesp == null) namesp = "";\r
if (uri == null) uri = "";\r
string targetFile = "";\r
\r
\r
// Generate the code\r
\r
- CodeDomProvider p = provider != null ? provider : new CSharpCodeProvider ();\r
- ICodeGenerator gen = p.CreateGenerator ();\r
+ ICodeGenerator gen = provider.CreateGenerator ();\r
\r
TypedDataSetGenerator.Generate (dataset, codeNamespace, gen);\r
\r
\r
public void Error (string msg)\r
{\r
- throw new Exception (msg);\r
+ throw new ApplicationException (msg);\r
}\r
\r
public void Error (string msg, string param)\r
{\r
- throw new Exception (string.Format(msg,param));\r
+ throw new ApplicationException (string.Format(msg,param));\r
+ }\r
+\r
+ private string StripQuot (string input)\r
+ {\r
+ if (input.Length < 2)\r
+ return input;\r
+ if (input [0] == '"' && input [input.Length -1] == '"' ||\r
+ input [0] == '\'' && input [input.Length - 1] == '\'')\r
+ return input.Substring (1, input.Length - 2);\r
+ else\r
+ return language;\r
}\r
}\r
}\r