2 * Namespace: System.Web
6 * Contact: <gvaish@iitk.ac.in>
9 * (C) Gaurav Vaish (2002)
14 using System
.Collections
;
15 using System
.Reflection
;
17 namespace Mono
.Enumerations
19 public class EnumCheck
21 private string className
;
23 private EnumCheckAssemblyCollection ecac
= new EnumCheckAssemblyCollection();
25 public static string confFile
= "assemblies.xml";
27 public EnumCheck(string className
)
29 this.className
= className
;
35 ecac
.ConfigFile
= confFile
;
37 if(type
== null || !type
.IsEnum
)
39 System
.Console
.Write("-->Failed to load the enumeration: " + className
);
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()
55 foreach(string url
in ecac
)
59 Assembly assembly
= Assembly
.LoadFrom(url
);
60 foreach(Type t
in assembly
.GetTypes())
64 if(className
== t
.ToString())
70 } catch(BadImageFormatException
)
72 } catch(ReflectionTypeLoadException
)
74 } catch(ArgumentException
)
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"))
98 EnumCheck check
= null;
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);
113 foreach(string clName
in args
)
115 check
= new EnumCheck(clName
);
117 System
.Console
.WriteLine("\n");
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)
126 check
= new EnumCheck(clName
);
128 System
.Console
.WriteLine("\n");