" /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
+ " /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
{\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
foreach (string fileName in schemaNames)\r
{\r
StreamReader sr = new StreamReader (fileName);\r
- schemas.Add (XmlSchema.Read (sr, null));\r
+ schemas.Add (XmlSchema.Read (sr, new ValidationEventHandler (HandleValidationError)));\r
sr.Close ();\r
\r
if (targetFile == "") targetFile = Path.GetFileNameWithoutExtension (fileName);\r
else\r
{\r
foreach (XmlSchema schema in schemas) {\r
- if (!schema.IsCompiled) schema.Compile (null);\r
- foreach (XmlSchemaObject ob in schema.Items)\r
- if (ob is XmlSchemaElement)\r
- qnames.Add (((XmlSchemaElement)ob).QualifiedName);\r
+ if (!schema.IsCompiled) schema.Compile (new ValidationEventHandler (HandleValidationError));\r
+ foreach (XmlSchemaElement el in schema.Elements.Values)\r
+ if (!qnames.Contains (el.QualifiedName))\r
+ qnames.Add (el.QualifiedName);\r
}\r
}\r
\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
Console.WriteLine ("Written file " + genFile);\r
}\r
\r
+ void HandleValidationError (object o, ValidationEventArgs e)\r
+ {\r
+ Console.WriteLine ("{0}: {1} {2}",\r
+ e.Severity == XmlSeverityType.Error ? "Error" : "Warning",\r
+ e.Message,\r
+ e.Exception != null ? e.Exception.Message : null);\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