On the other hand, if you're writing a quick and dirty utility to update a bunch of your .cs files, then you can do it like this (as long as you realize that all of the projects that have a file that you've modified will need to be recompiled after you're done).
- Read the .cs file in using File.ReadLines()
- Turn the array into a List and Insert your text
- Write the file back using File.WriteAllLines().
string[] lines = File.ReadAllLines(FileName);
List<string> lineList = lines.ToList();
int insertPos = lineList.Count - 2;
lineList.Insert(insertPos++, " #region UniversalLifePrm");
lineList.Insert(insertPos++, " public static T UniversalLifePrm<T>(string configName)");
lineList.Insert(insertPos++, "// Put the rest of your code here.");
lineList.Insert(insertPos, " #endregion");
File.WriteAllLines(FileName, lineList.ToArray());
~~Bonnie DeWitt [C# MVP]
http://geek-goddess-bonnie.blogspot.com
No comments:
Post a Comment