home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETSDK / SETUP.EXE / netfxsd1.cab / FL_ResDump_cs________.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Encoding:
Text File  |  2001-08-21  |  3.0 KB  |  105 lines

  1. // Self contained resource sample that iterates the resourcs in resource files
  2.  
  3. using System;
  4. using System.Collections;
  5. using System.IO;
  6. using System.Resources;
  7.  
  8. class MainApp {
  9.     public static int Main(String[] args) {
  10.  
  11.         ResDumpArgParser ap = new ResDumpArgParser();
  12.         if (!ap.Parse(args)) {
  13.             // An error occurrend while parsing
  14.             return 1;
  15.         }
  16.     
  17.         // Iterate through the English resources
  18.         ResourceReader rr;
  19.         try {
  20.             rr = new ResourceReader(ap.filename);
  21.             IDictionaryEnumerator de = rr.GetEnumerator();
  22.  
  23.             while (de.MoveNext()) {
  24.                 Console.WriteLine(de.Key + "\t" + " - " + de.Value);
  25.             }
  26.         }
  27.  
  28.         catch (FileNotFoundException e) {
  29.             Console.WriteLine(e.ToString());
  30.             Console.WriteLine("File not found - " + ap.filename);
  31.         }
  32.         catch (Exception e) {
  33.             Console.WriteLine(e.ToString());
  34.         }
  35.     return 0;
  36.     }
  37. }
  38.  
  39. ///////////////////////////////////////////////////////////////////////////////
  40.  
  41. class ResDumpArgParser : ArgParser {
  42.  
  43.     // Members identifying command-line argument settings
  44.     public string filename = "";
  45.  
  46.  
  47.     // Give the set of valid command-line switches to the base class
  48.     public ResDumpArgParser() : base(new string[] { "?"}) { 
  49.     }
  50.  
  51.  
  52.     // Shows application's usage info and also reports command-line argument errors.
  53.     public override void OnUsage(String errorInfo) {
  54.         if (errorInfo != null) {
  55.             // An command-line argument error occurred, report it to user
  56.             // errInfo identifies the argument that is in error.
  57.             Console.WriteLine("Command-line switch error: {0}\n", errorInfo);
  58.         }
  59.  
  60.         Console.WriteLine("Usage: ResDump input-filename...");
  61.         Console.WriteLine("   -?  Show this usage information");
  62.     }
  63.  
  64.  
  65.     // Called for each non-switch command-line argument (filespecs)
  66.     protected override SwitchStatus OnNonSwitch(String switchValue) {
  67.         SwitchStatus ss = SwitchStatus.NoError;
  68.         filename = switchValue;
  69.         return(ss);
  70.     }
  71.  
  72.  
  73.     // Called for each switch command-line argument
  74.     protected override SwitchStatus OnSwitch(String switchSymbol, String switchValue) {
  75.         // NOTE: For case-insensitive switches, 
  76.         //       switchSymbol will contain all lower-case characters
  77.  
  78.         SwitchStatus ss = SwitchStatus.NoError;
  79.         switch (switchSymbol) {  
  80.  
  81.         case "?":   // User wants to see Usage
  82.             ss = SwitchStatus.ShowUsage; 
  83.             break;
  84.         default:
  85.             Console.WriteLine("Invalid switch: \"" + switchSymbol + "\".\n");
  86.             ss = SwitchStatus.Error; 
  87.             break;
  88.         }
  89.         return(ss);
  90.     }
  91.  
  92.  
  93.     // Called when all command-line arguments have been parsed
  94.     protected override SwitchStatus OnDoneParse() {
  95.         SwitchStatus ss = SwitchStatus.NoError;
  96.         // Sort all the filenames in the list
  97.         if (filename == "") {
  98.             Console.WriteLine("Must include 1 filename.");
  99.             ss = SwitchStatus.Error;
  100.         }
  101.         return(ss);
  102.     }
  103. }
  104.  
  105.