about this book

Metaprogramming in .NET requires you to move beyond the canonical material of interfaces, virtual methods, and events to more advanced and probably unknown concepts like reflection, assembly rewriting, expressions, and code analysis. If you’ve never encountered these APIs or techniques, it may feel a little daunting to even approach the first chapter!

We don’t “pontificate on the profound”—that is, although you’ll be exposed to new ideas, you won’t read about every extreme, esoteric corner of metaprogramming. Rather, you’ll be guided into these realms with an understanding of why you need to learn about these techniques. At the end of the day, we want you to not only gain an appreciation of how powerful metaprogramming is, but how to use this material in your day-to-day coding experiences.

Throughout this book, you’ll learn about different techniques and frameworks. They all have their strengths and weaknesses. Some work well in some areas of an application, and others shine somewhere else. You’ll understand when it’s best to use one tool, and what the trade-offs are in using a particular approach.

Roadmap

Who should read this book?

If you’re a .NET developer who wants not only to learn more than just how to “do” dependency injection and “use” controllers, but also to create frameworks that provide useful services to other developers, then this book is for you. Many popular .NET frameworks that make hard problems simple usually end up using one or more of the techniques presented in this book, but they structure their work in such a way that you probably don’t see it (which is usually a good thing). If you want to create these components, you’ll need to know how these techniques work, and this book provides that guidance.

We assume that you’re familiar with the base competencies that a .NET developer would have. For example, we expect that you know what a class is, the difference between a virtual and a non-virtual method, and what sealed means in C#.

Code conventions and downloads

This book contains numerous code examples. All the code is in a fixed-width font like this to separate it from ordinary text. Code members such as method names, class names, and so on are also in a fixed-width font.

Source code examples in this book are fairly close to the samples that you’ll find online. But for brevity’s sake, we may have removed material such as comments from the code to fit it well within the text.

Annotations accompany many of the source code listings, highlighting important concepts. In some cases, numbered bullets link to explanations that follow the listing.

The source code for the examples in the book is available for download from the publisher’s website at www.manning.com/Metaprogrammingin.Net. It is also available from http://metadotnetbook.codeplex.com.

To run the samples, you’ll need to download some of the tools and languages we use in this book. We provide links in the text to places where you can get the relevant files.

Author Online

The purchase of Metaprogramming in .NET includes free access to a private web forum run by Manning Publications, where you can make comments about the book, ask technical questions, and receive help from the authors and from other users. To access the forum and subscribe to it, point your web browser at www.manning.com/Metaprogrammingin.NET. This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct on the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and authors can take place. It’s not a commitment to any specific amount of participation on the part of the authors, whose contributions to the forum remain voluntary (and unpaid). We suggest you try asking the authors some challenging questions, lest their interest stray!

The Author Online forum and archives of previous discussions will be accessible from the publisher’s web site as long as the book is in print.

About the authors

KEVIN HAZZARD is a director for CapTech Consulting, a management consulting and software development firm of 375 consultants based in Richmond, Va., with offices in Philadelphia, Charlotte, and Washington, D.C. Kevin was a Microsoft C# MVP for years until moving into the Windows Azure MVP group. Although his head is in the clouds these days, Kevin still considers himself to be a languages guy, focusing most of his attention on functional and dynamic languages like F# and Python.

Kevin has served as a leader for the Richmond Code Camp (http://richmondcodecamp.org), the Richmond .NET User Group, the Richmond SQL Server User Group, the Richmond Software Craftsmanship Group, and the Mid-Atlantic Developer Expo (http://madexpo.us). He also speaks regularly at conferences around the Midwest and Mid-Atlantic states, directing most of his attention these days to teaching programming and robotics to children.

Kevin taught computer programming language courses in the Virginia Community College system for more than a decade, but gave that up in 2011 to run for office and become elected to his county’s K-12 School Board. You can follow Kevin at http://twitter.com/KevinHazzard or befriend him at http://facebook.com/wkhazzard to stay in touch.

JASON BOCK is a principal lead consultant for Magenic (www.magenic.com) and a Microsoft C# MVP. He’s worked on a number of business applications using a diverse set of substrates and languages, such as C#, .NET, and Java. He’s the also the author of Applied .NET Attributes (Apress, 2003), CIL Programming: Under the Hood of .NET (Apress, 2002), and Visual Basic 6 Win32 API Tutorial (Wrox, 1998). He’s written numerous articles on software development, has presented at a number of conferences and user groups, and is a leader of the Twin Cities Code Camp (www.twincitiescodecamp.com). Jason holds a master’s degree in electrical engineering from Marquette University. Visit his website at www.jasonbock.net.