Advertisement
Guest User

Untitled

a guest
Jul 21st, 2010
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml;
  6.  
  7. using System.Xml.Linq;
  8.  
  9. namespace ConsoleApplication1
  10. {
  11.     class Program
  12.     {
  13.  
  14.         public class MyConfig
  15.         {
  16.             public string DisplayName { get; set; }
  17.             public string IsDebugOnly { get; set; }
  18.             public string IsReleaseOnly { get; set; }
  19.             public string PackageFilesAs { get; set; }
  20.             public string ShouldBuild { get; set; }
  21.         }
  22.  
  23.         public static void Main(string[] args)
  24.         {
  25.             var ConfigsFound = new List<MyConfig>();
  26.             string[] allLines = System.IO.File.ReadAllLines(@"C:\foo.vdproj");
  27.             int configStartIndex = 0;
  28.             List<int> configNameAt = new List<int>();
  29.  
  30.             for (int i = 0; i < allLines.Length - 1; i++)
  31.             {
  32.  
  33.                 string line = allLines[i];
  34.                 if (string.IsNullOrWhiteSpace(line))
  35.                     continue;
  36.  
  37.                 //parse out the configurations in this vdproj
  38.                 if (line == "\t\"Configurations\"")
  39.                 {
  40.                     //read ahead to determine the end of the config block.
  41.                     configStartIndex = i;
  42.                 }
  43.  
  44.                 if (line.StartsWith("\t\t\""))
  45.                 {
  46.                     //this is the beginning of a named configuration.
  47.                     configNameAt.Add(i);
  48.                 }
  49.  
  50.                 if (line == "\t}" && configStartIndex>0)
  51.                 {
  52.                     //end of config section; crater out!
  53.                     break;
  54.                 }              
  55.             }
  56.  
  57.             //build a list of config sections!
  58.             foreach (int configStartLine in configNameAt)
  59.             {
  60.                 int propertiesStartAt = configStartLine + 3;
  61.                 MyConfig config = new MyConfig { DisplayName = GetValueFromLine(propertiesStartAt) };
  62.                 config.IsDebugOnly = GetValueFromLine(propertiesStartAt + 1);
  63.                 config.IsReleaseOnly = GetValueFromLine(propertiesStartAt + 2);
  64.                 config.PackageFilesAs = GetValueFromLine(propertiesStartAt + 3);
  65.                 config.ShouldBuild = GetValueFromLine(propertiesStartAt + 4);
  66.                 ConfigsFound.Add(config);
  67.             }
  68.  
  69.             foreach (var item in ConfigsFound)
  70.             {
  71.                 Console.WriteLine(item.DisplayName + " " + item.IsDebugOnly);
  72.             }
  73.             Console.ReadLine();
  74.            
  75.         }
  76.  
  77.         private static string GetValueFromLine(int lineNumber)
  78.         {
  79.             string lineText = System.IO.File.ReadAllLines(@"C:\foo.vdproj").Skip(lineNumber-1).Take(1).SingleOrDefault();
  80.             // now have something like "    DisplayName = "8:Release""
  81.             lineText = lineText.Trim().Replace(" = ", "=");
  82.             return  lineText.Split('=')[1].Trim('"');
  83.         }
  84.  
  85.  
  86.     }
  87.  
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement