2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / tools / misc / EnumCheck.cs
blob8c564cc79564e77a17bb36c6a33a3f410aa60d62
1 /**
2 * Namespace: System.Web
3 * Class: EnumCheck
5 * Author: Gaurav Vaish
6 * Contact: <gvaish@iitk.ac.in>
7 * Status: 100%
9 * (C) Gaurav Vaish (2002)
12 using System;
13 using System.Xml;
14 using System.Collections;
15 using System.Reflection;
17 namespace Mono.Enumerations
19 public class EnumCheck
21 private string className;
22 private Type type;
23 private EnumCheckAssemblyCollection ecac = new EnumCheckAssemblyCollection();
25 public static string confFile = "assemblies.xml";
27 public EnumCheck(string className)
29 this.className = className;
30 ecac.Parse();
33 public void Display()
35 ecac.ConfigFile = confFile;
36 LoadType();
37 if(type == null || !type.IsEnum)
39 System.Console.Write("-->Failed to load the enumeration: " + className);
40 return;
42 Array ar = Enum.GetValues(type);
43 System.Console.WriteLine("-->Enumeration: {0}", type.ToString());
44 for(int i=0; i < ar.Length; i++)
46 Enum b = (Enum)ar.GetValue(i);
47 System.Console.Write(" {0}", Enum.Format(type, b, "G"));
48 System.Console.WriteLine(" ({0}) ", Enum.Format(type, b, "D"));
52 private void LoadType()
54 type = null;
55 foreach(string url in ecac)
57 try
59 Assembly assembly = Assembly.LoadFrom(url);
60 foreach(Type t in assembly.GetTypes())
62 if(!t.IsEnum)
63 continue;
64 if(className == t.ToString())
66 type = t;
67 break;
70 } catch(BadImageFormatException)
72 } catch(ReflectionTypeLoadException)
74 } catch(ArgumentException)
77 if(type != null)
78 return;
82 public static void PrintUsage()
84 System.Console.WriteLine("Usage:");
85 System.Console.WriteLine("EnumCheck [<enum> [<enum> [... ] ] ]");
86 System.Console.WriteLine("");
87 System.Console.WriteLine("enum := <namespace>[.<subnamespace>[...]].enum_name");
88 System.Console.WriteLine("");
91 public static void Main(string[] args)
93 if(args.Length > 0 && (args[0] == "--help" || args[0] == "-h"))
95 PrintUsage();
96 return;
98 EnumCheck check = null;
99 string bdir;
100 System.Console.Write("Enter assembly configuration file [{0}]:", confFile);
101 //System.Console.Write("[{0}]: ", confFile);
102 bdir = System.Console.ReadLine();
103 while(bdir.EndsWith("/") || bdir.EndsWith("\\"))
105 bdir = bdir.Substring(0, bdir.Length - 1);
107 if(bdir != "")
109 confFile = bdir;
111 if(args.Length != 0)
113 foreach(string clName in args)
115 check = new EnumCheck(clName);
116 check.Display();
117 System.Console.WriteLine("\n");
120 while(true)
122 System.Console.Write("Enter the name of the Enumeration (end to stop): ");
123 string clName = System.Console.ReadLine();
124 if(clName == "stop" || clName == "end" || clName.Length == 0)
125 break;
126 check = new EnumCheck(clName);
127 check.Display();
128 System.Console.WriteLine("\n");