MetaProgramming icon indicating copy to clipboard operation
MetaProgramming copied to clipboard

Metaprogramming .Net samples

MetaProgramming .Net samples

#Metaprogramming via scripting

  • Brilliant sample from 'Metaprogramming in .Net' book
  • Scripting: Roslyn CTP vs. IronPython
  • ScriptCS eval()-like
  • Roslyn CTP: scripting and results as dynamic
  • IronPython: scripting, DLR and results as dynamic
    • C# code
    • .py code

#Dynamically generating .Net assembly at runtime

  • Roslyn CTP: build and load assembly in memory
  • CodeDOM
    • build and load assembly in memory
    • C# 4.0 and 5.0 features, not supported by Roslyn CTP yet

#Metaprogramming via runtime code generation

  • Hardcoded C# rule: ~900ms to run 1000 iterations
  • Roslyn CTP: scripting and statically typed results: ~950ms to run 1000 iterations
  • DLR i.e. Dynamic Language Runtime with ExpressionTrees: ~1200ms to run 1000 iterations

#Code-as-Data approach

  • Roslyn CTP convert VB → C#, and back
  • Roslyn CTP and T4
    • Runtime template transformation using T4
    • Generate types, models and algorithms from JSON input using Roslyn CTP

#Introspection

#Nemerle: compile-time macro

  • Nemerle macro: compile- with run- time execution
    • compile-time macro
    • compile-time macro usage
    • introduce new syntax keyword fault
    • new syntax keyword fault usage