HAPPY BOOKSGIVING
Use code BOOKSGIVING during checkout to save 40%-55% on books and eBooks. Shop now.
Register your product to gain access to bonus material or receive a coupon.
“Once this skill is within your everyday comfort zone, it will give your productivity a boost and increase your value to your team. I encourage you to add the techniques outlined in this book to your toolset and to use them to develop your own workbench of generative tools. In doing so, I’m confident you’ll improve your capabilities, and what’s more, have fun doing so.”
–From the Foreword by Gareth Jones, Developer Architect, Visual Studio®, Microsoft
Enlist Visual Studio’s Built-in Code Generation Tools to Write Better Software Faster
Automatic code generation can dramatically increase your productivity, improve code quality and maintainability, promote reuse, and help you extend best practices throughout your development organization. .NET and Visual Studio contain many powerful, code-generation tools--and this book shows you how to succeed with all of them. With Practical Code Generation in .NET, spend less time writing monotonous, repetitive code--leaving more time to address troublesome areas!
Microsoft MVP Peter Vogel covers code generation with Visual Studio 2010, 2008, and 2005, as well as all recent versions of .NET, including .NET 4.0. You’ll learn when enlisting code generation makes sense and how to design solutions that build on the skills and resources you already have.
Writing for experienced programmers, Vogel shows how to generate reliable code using procedural code, Visual Studio add-ins, XML, configuration files, and more--including Microsoft’s innovative CodeDOM technology for generating code in multiple languages. He brings everything together in three complete, chapter-length case studies.
Coverage includes
• Understanding the structure of .NET code-generation solutions and best practices for architecting them
• Creating Visual Studio add-ins that quickly integrate code generation into day-to-day activities
• Using objects and methods to add or remove project components
• Using text insertion to generate code using any tool--even standard string handling functions
• Working with the specific features of C#, Visual Basic .NET, and ASP.NET
• Generating more concise code with .NET’s new Text Template Transformation Toolkit (T4)
• Building code-generation solutions with Visual Studio templates, attributes, and custom tools
• Distributing code-generation solutions
Practical Code Generation in .NET: Generating a Connection String Manager
Download the sample pages (includes Chapter 9 and Index)
Foreword . . . xiv
Preface . . . xvi
Acknowledgments . . . xx
About the Author . . . xxi
Chapter 1 Introducing Code Generation . . . 1
Repetitive Code: Your History . . . 2
Copy-and-Paste . . . 2
General-Purpose Code . . . 3
Benefits of Code Generation . . . 4
When to Use Code Generation . . .7
Best Practices in Code-Generation Solutions . . . 10
Code-Generation Process . . . 11
Code-Generation Tools . . .12
Model-Driven Architecture, Declarative Programming, and Code Generation . . . 14
Model-Driven Architecture . . . 14
Declarative Programming . . . 17
PART I: TOOLS . . . 19
Chapter 2 Integrating with Visual Studio . . . 21
Design-Time Integration . . .22
Starting Your Visual Studio Add-In . . . 23
Laying the Foundation . . . 24
Integrating with Visual Studio . . . 27
Writing a Generation Class in Visual Studio . . . 30
Working with COM . . .31
Debugging Issues in Visual Studio 2005/2008 . . . 32
The OnConnection Method . . .34
Removing Add-In Menus . . . 35
Creating a Menu-Driven User Interface . . . 36
Extending Your Menus . . . 36
Adding Additional Menus . . . 37
Finding the Menu . . . 38
Adding the Menu Item . . . 40
Supporting Multiple Menu Items . . . 42
Creating Submenus . . .43
Adding Submenus . . . 44
Context Menus . . . 44
Accessing the Context . . . 46
Working with Visual Studio Windows . . . 49
Using the Task List Window . . .49
Retrieving Selected Items . . . 50
Writing Messages to the Output Window and the TaskList . . . 51
AutoNavigate in Visual Studio 2005 . . .55
Final Touches . . . 57
Responding to Events . . . 58
Simple Events . . . 58
Filtered Events . . . 60
Working with Document Events . . . 61
Extracting Event Packages . . . 63
Finishing Events . . . 64
Accepting Input . . . 65
Options . . . 65
Creating a Dockable Window . . . 65
Saving Input Values . . .69
Adding an Options Tab . . . 71
Accessing and Saving Option Properties . . . 73
Integrating with Visual Studio . . . 76
Chapter 3 Manipulating Project Components . . . 77
The Code Model . . . 78
Code Model Caveats . . . 79