2 * Namespace: System.Web
\r
5 * Author: Gaurav Vaish
\r
6 * Contact: <gvaish@iitk.ac.in>
\r
9 * (C) Gaurav Vaish (2002)
\r
14 using System.Collections;
\r
15 using System.Reflection;
\r
17 namespace Mono.Enumerations
\r
19 public class EnumCheck
\r
21 private string className;
\r
23 private EnumCheckAssemblyCollection ecac = new EnumCheckAssemblyCollection();
\r
25 public static string confFile = "assemblies.xml";
\r
27 public EnumCheck(string className)
\r
29 this.className = className;
\r
33 public void Display()
\r
35 ecac.ConfigFile = confFile;
\r
37 if(type == null || !type.IsEnum)
\r
39 System.Console.Write("-->Failed to load the enumeration: " + className);
\r
42 Array ar = Enum.GetValues(type);
\r
43 System.Console.WriteLine("-->Enumeration: {0}", type.ToString());
\r
44 for(int i=0; i < ar.Length; i++)
\r
46 Enum b = (Enum)ar.GetValue(i);
\r
47 System.Console.Write(" {0}", Enum.Format(type, b, "G"));
\r
48 System.Console.WriteLine(" ({0}) ", Enum.Format(type, b, "D"));
\r
52 private void LoadType()
\r
55 foreach(string url in ecac)
\r
59 Assembly assembly = Assembly.LoadFrom(url);
\r
60 foreach(Type t in assembly.GetTypes())
\r
64 if(className == t.ToString())
\r
70 } catch(BadImageFormatException)
\r
72 } catch(ReflectionTypeLoadException)
\r
74 } catch(ArgumentException)
\r
82 public static void PrintUsage()
\r
84 System.Console.WriteLine("Usage:");
\r
85 System.Console.WriteLine("EnumCheck [<enum> [<enum> [... ] ] ]");
\r
86 System.Console.WriteLine("");
\r
87 System.Console.WriteLine("enum := <namespace>[.<subnamespace>[...]].enum_name");
\r
88 System.Console.WriteLine("");
\r
91 public static void Main(string[] args)
\r
93 if(args.Length > 0 && (args[0] == "--help" || args[0] == "-h"))
\r
98 EnumCheck check = null;
\r
100 System.Console.Write("Enter assembly configuration file [{0}]:", confFile);
\r
101 //System.Console.Write("[{0}]: ", confFile);
\r
102 bdir = System.Console.ReadLine();
\r
103 while(bdir.EndsWith("/") || bdir.EndsWith("\\"))
\r
105 bdir = bdir.Substring(0, bdir.Length - 1);
\r
111 if(args.Length != 0)
\r
113 foreach(string clName in args)
\r
115 check = new EnumCheck(clName);
\r
117 System.Console.WriteLine("\n");
\r
122 System.Console.Write("Enter the name of the Enumeration (end to stop): ");
\r
123 string clName = System.Console.ReadLine();
\r
124 if(clName == "stop" || clName == "end" || clName.Length == 0)
\r
126 check = new EnumCheck(clName);
\r
128 System.Console.WriteLine("\n");
\r