2. What is it?
• Metaprogramming is most easily defined as
beside-programming or after-programming
– Late-binding
– Runtime compilation
– Code generation
3. Where is it?
• You’ve already seen and used it, most likely
– Microsoft
• System.Reflection
• CodeDom
• Emit
• T4
• Dynamic Language Runtime (DLR, dynamic keyword)
Generating Intermediate Language (IL) with Expression Trees
• Roslyn (compiler as a service)
• Enterprise Library’s Policy Injection block
• Generics
– Aspect Oriented Programming
4. Why?
• DRY – Don’t repeat yourself
– don’t duplicate authority
– Boiler-plate code
– Simplify manual coding hand work
• Update the entire system at a single point rather than
search and find by hand
• Lack of higher order functions
• Make parts of the application update or adjust
based on each other at the click of a button
15. Final words
• “metaprogramming is all about making software simpler
and reusable. However, rather than depending strictly on
language features to reduce code complexity or to increase
reusability, metaprogramming achieves those goals
through a variety of libraries and coding techniques”
• “For the most part however, metaprogramming is a set of
language independent skills.”
• “As perceived complexity from the end user's standpoint
goes down, internal complexity of the design often goes
up. Complexity reduction when metaprogramming follows
the same rules. To achieve simplicity on the outside, the
code on the inside of a metaprogramming-enabled
component typically takes on some added Responsibilities”
16. More about me
• http://imaginarydevelopment.blogspot.com
• https://www.ohloh.net/accounts/Maslow
• http://stackoverflow.com/users/57883/maslo
w
18. Appendix
• Roslyn Code source
– http://code.msdn.microsoft.com/Implementing-a-Code-
Action-28579fb1
• Many of my T4’s available
– http://ideone.com/imaginarydevelopment/t4
• Emit Full source
– http://breusable.codeplex.com/SourceControl
/changeset/view/92288#1863265
• AOP – was a little deeper than I thought
we would have time for
– http://www.sharpcrafters.com/
– http://www.mono-project.com/Cecil
Notes de l'éditeur
Metaprogramming in .NET MEAP v6 pg 5.
.net 1.1
.net 1.1
Released 2005 out of band from VS2005 Notice the lack of whitespacing?
If this were linq to sql(or EF) the expression part would be easier to see/discuss Late binding, questionable practices, and much more!