Beispiel #1
0
        public static void IncludeLineInSpringConfig(string configFileName, string textToFind, string lineToInclude, int shift = 1)
        {
            List <string> configCode = File.ReadAllLines(configFileName).ToList();
            PlaceInFile   place      = FindLastLineThatContainText(configCode, textToFind);

            if (place == null)
            {
                throw new Exception("Cannot find place for adding line in " + configFileName);
            }
            configCode.Insert(place.LineNumber + shift, place.Spaces + lineToInclude);
            File.WriteAllLines(configFileName, configCode);
        }
Beispiel #2
0
        public static void AddMethodToClass(string classFileName, IEnumerable <string> methodCode)
        {
            List <string> classCode = File.ReadAllLines(classFileName).ToList();
            PlaceInFile   place     = FindPlaceForMethod(classCode);

            if (place == null)
            {
                throw new Exception("Cannot find place for adding new method in " + classFileName);
            }
            var indentedMethodCode = methodCode.IndentAllLines(place.Spaces);

            classCode.InsertRange(place.LineNumber, indentedMethodCode);
            File.WriteAllLines(classFileName, classCode);
        }
Beispiel #3
0
        public static void IncludeInProject(string projectFileName, string fileToInclude, bool needCompile = true)
        {
            List <string> projectCode = File.ReadAllLines(projectFileName).ToList();
            PlaceInFile   place       = FindPlaceForIncludeInProject(projectCode);

            if (place == null)
            {
                throw new Exception("Cannot find \"<Compile Include\" section in the " + projectFileName);
            }
            string includeLine = "<" + (needCompile ? "Compile" : "None") + " Include=\"" + fileToInclude + "\" />";

            projectCode.Insert(place.LineNumber + 1, place.Spaces + includeLine);
            File.WriteAllLines(projectFileName, projectCode);
        }