Chapter 4. Accelerating Delivery
In this chapter we’ll work through different types of text extraction and manipulation. This functionality ties into creating code generators, which take over the task of writing repetitive infrastructure code, thereby eliminating grunt work. PowerShell’s ability to work in this way—reading text, XML, and DLL metadata—enables productivity and consistency while driving up the quality of the deliverable.
Being able to rip through numerous source code files looking for text in a specific context and extracting key information is super useful; primarily, it means we can locate key information quickly. Plus, because we can generate a .NET object with properties, we can easily pipe the results and do more work easily. For example, we can:
Export the results to a CSV and do analysis on them with Excel.
Catalog strings for use by QA/QC.
Create lists of classes, methods, and functions.
Let’s get started exploring this useful and timesaving functionality.
Scanning for const Definitions
The examples in this section read C# files looking for strings containing the word const, extracting the variable name and value. Scanning for strings across files takes many forms—searching SQL files, PowerShell scripts, JavaScript files, and HTML files, just to name a few. Once the information is extracted, you can use it again in many ways—for example, cataloging strings for internationalization, analyzing code, creating indexes of class methods and functions, and locating global ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access