//
-// genxs.cs
+// sgen.cs
//
-// Author:
+// Authors:
// Lluis Sanchez Gual (lluis@ximian.com)
+// Atsushi Enomoto (atsushi@ximian.com)
//
// Copyright (C) 2003 Ximian, Inc.
+// Copyright (C) 2006 Novell, Inc.
//
using System;
bool verbose;
string unknownArg;
-#if NET_2_0
public int Run (string[] args)
{
}
catch {}
- if (asm == null)
- asm = Assembly.LoadFrom (assembly);
-
-
+ if (asm == null) {
+ try {
+ asm = Assembly.LoadFrom (assembly);
+ } catch {
+ Console.WriteLine ("Specified assembly cannot be loaded.");
+ Console.WriteLine ();
+ return 1;
+ }
+ }
ArrayList userTypes = new ArrayList ();
ArrayList maps = new ArrayList ();
XmlReflectionImporter imp = new XmlReflectionImporter ();
if (verbose)
Console.WriteLine ("Generating serializer for the following types:");
-
- foreach (Type t in asm.GetTypes())
- {
- try {
- maps.Add (imp.ImportTypeMapping (t));
- if (types == null || types.Contains (t.ToString())) {
+
+ if (types == null) {
+ foreach (Type t in asm.GetTypes ()) {
+ try {
+ maps.Add (imp.ImportTypeMapping (t));
userTypes.Add (t);
- if (verbose) Console.WriteLine (" - " + t);
+ if (verbose)
+ Console.WriteLine( " - " + t );
+ } catch (InvalidOperationException ex) {
+ if (verbose)
+ Console.WriteLine (" - Warning: " + ex.Message);
+ } catch (NotImplementedException ex) {
+ if (verbose) {
+ Console.WriteLine (" - Warning: ignoring '" + t + "'");
+ Console.WriteLine (" " + ex.Message);
+ }
+ } catch (NotSupportedException ex) {
+ if (verbose)
+ Console.WriteLine (" - Warning: " + ex.Message);
}
}
- catch (Exception ex)
- {
- if (verbose) {
- Console.WriteLine (" - Warning: ignoring '" + t + "'");
- Console.WriteLine (" " + ex.Message);
+ } else {
+ foreach (string type in types) {
+ try {
+ Type t = asm.GetType (type);
+ maps.Add (imp.ImportTypeMapping (t));
+ userTypes.Add (t);
+ if (verbose)
+ Console.WriteLine (" - " + t);
+ } catch (InvalidOperationException ex) {
+ if (verbose)
+ Console.WriteLine (" - Warning: " + ex.Message);
+ } catch (NotImplementedException ex) {
+ if (verbose) {
+ Console.WriteLine (" - Warning: ignoring '" + type + "'");
+ Console.WriteLine (" " + ex.Message);
+ }
+ } catch (NotSupportedException ex) {
+ if (verbose)
+ Console.WriteLine (" - Warning: " + ex.Message);
}
}
}
-
+
if (verbose)
Console.WriteLine ();
return 0;
}
-#else
- public int Run (string[] args)
- {
- Console.WriteLine ("This tool is only supported in Mono 2.0");
- return 1;
- }
-
-#endif
void ParseArgs (string[] args)
{
foreach (string arg in args)
{
-
- if (!arg.StartsWith ("--") && !arg.StartsWith ("/"))
+ int index = arg.Length > 2 && arg [0] == '-' && arg [1] == '-' ? 2 : -1;
+ index = index >= 0 ? index : arg.Length > 0 && arg [0] == '/' ? 1 : -1;
+ if (index < 0)
{
assembly = arg;
continue;
}
- int i = arg.IndexOf (":");
+ int i = arg.IndexOf (':', index);
if (i == -1) i = arg.Length;
- string op = arg.Substring (1,i-1);
- string param = (i<arg.Length-1) ? arg.Substring (i+1) : "";
-
+ string op = arg.Substring (index, i - index).ToLowerInvariant ();
+ string param = (i < arg.Length - index) ? arg.Substring (i + 1) : "";
if (op == "assembly" || op == "a") {
assembly = param;
}
}
}
}
+