Metaprogramming in .NET
Kevin Hazzard and Jason Bock
Foreword by Rockford Lhotka
  • December 2012
  • ISBN 9781617290268
  • 360 pages
  • printed in black & white

An excellent way to start fully using the power of metaprogramming.

From the Foreword by Rockford Lhotka, Creator of the CSLA .NET Framework

Metaprogramming in .NET is designed to help readers understand the basic concepts, advantages and potential pitfalls of metaprogramming. It introduces core concepts in clear, easy-to-follow language and then it takes you on a deep dive into the tools and techniques you'll use to implement them in your .NET code. You'll explore plenty of real-world examples that reinforce key concepts. When you finish, you'll be able to build high-performance, metaprogramming-enabled software with confidence.

Table of Contents detailed table of contents


preface acknowledgments about this book about the cover illustration




Part 1 Demystifying metaprogramming

1. Chapter 1 Metaprogramming concepts

1.1. Definitions of metaprogramming

1.2. Examples of metaprogramming

1.3. Summary

2. Chapter 2 Exploring code and metadata with reflection

2.1. The need for reflection

2.2. Reading metadata and executing code

2.3. Impractical uses of reflection

2.4. Practical uses of reflection

2.5. Summary

Part 2 Techniques for generating code

3. Chapter 3 The Text Template Transformation Toolkit (T4)

3.1. Thinking of generics as templates

3.2. Introducing T4

3.3. More useful T4 examples

3.4. T4 fundamentals

3.5. Using T4 inside Visual Studio

3.6. Summary

4. Chapter 4 Generating code with the CodeDOM

4.1. Understanding the CodeDOM

4.2. The code provider classes

4.3. Adding objects to a code graph

4.4. Metaprogramming with the CodeDOM

4.5. Summary

5. Chapter 5 Generating code with Reflection.Emit

5.1. Why Emitter classes?

5.2. An overview of assembly internals

5.3. A lightning tour of opcodes

5.4. Creating dynamic assemblies

5.5. Lightweight code generation with dynamic methods

5.6. Summary

6. Chapter 6 Generating code with expressions

6.1. Expression-oriented programming

6.2. Making dynamic methods with LINQ Expressions

6.3. Using expressions effectively

6.4. Evolving expression trees

6.5. Summary

7. Chapter 7 Generating code with IL rewriting

7.1. The case for code injection

7.2. Creating an injection framework

7.3. Debugging injected code

7.4. Summary

Part 3 Languages and tools

8. Chapter 8 The Dynamic Language Runtime

8.1. The simplest dynamic classes

8.2. The DLR hosting model

8.3. Summary

9. Chapter 9 Languages and tools

9.1. A survey of languages

9.2. A survey of tools

9.3. Summary

10. Chapter 10 Managing the .NET Compiler

10.1. Opening up the compiler

10.2. Understanding the basics of Roslyn

10.3. Interacting with code in Visual Studio

10.4. Summary

© 2014 Manning Publications Co.

About the Technology

When you write programs that create or modify other programs, you are metaprogramming. In .NET, you can use reflection as well as newer concepts like code generation and scriptable software. The emerging Roslyn project exposes the .NET compiler as an interactive API, allowing compile-time code analysis and just-in-time refactoring.

About the book

Metaprogramming in .NET is a practical introduction to the use of metaprogramming to improve the performance and maintainability of your code. This book avoids abstract theory and instead teaches you solid practices you'll find useful immediately. It introduces core concepts like code generation and application composition in clear, easy-to-follow language, and then it takes you on a deep dive into the tools and techniques that will help you implement them in your .NET applications.

Written for readers comfortable with C# and the .NET framework—no prior experience with metaprogramming is required.

What's inside

  • Metaprogramming concepts in plain language
  • Creating scriptable software
  • Code generation techniques
  • The Dynamic Language Runtime

About the reader

Readers should be comfortable with C# and the .NET framework. No prior experience with metaprogramming is required.

About the authors

Kevin Hazzard is a Microsoft MVP, consultant, teacher, and developer community leader in the mid-Atlantic USA. Jason Bock is an author, Microsoft MVP, and the leader of the Twin Cities Code Camp.

  • combo $44.99 pBook + eBook
  • eBook $35.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks

A thorough and comprehensive distillation of the vast array of code generation options in .NET.

Harry Cummings, Softwire

An extensive collection of "aha!" discoveries on developing applications beyond the mere compiler.

William Lee, Qualcomm, Inc.

An excellent reference … insightful examples.

Arun Noronha, Guardian Protection Services