Sunday, August 28, 2011

DEV403 Dynamic and Metaprogramming in .NET 4

Presenter: Ivan Towlson
Apologies that this post is fairly nonsensical. I've put my raw NZ TechEd 2011 notes up here for my reference. I'd like to think that I'll refine them over time, but that probably won't be the case.
TechEd Online

What C# dynamic keyword does

dynamic keyword - "I know better than the compiler" - deferred look up until run time.

Old COM libraries - like Microsoft Office 2010.

No intellisense.

MVC ViewBag is of type dynamic. DynamicViewDataDictionary

Inherit from dynamic object. 

DynamicObject.TryInvokeMember

DynamicProgramming - "It's all just string diddling. Diddling is a technical term." 
"Really is is a fancy way of passing strings into a method."

named arguments

Runtime Code Generation

Activator.CreateInstance(type); // Very slow as it uses reflection

Expression.Compile() turns an abstract tree into executable code.

Turn reflection based code into compiled expression trees to improve performance.

Create a class that implements an interface at runtime. Interact with it at runtime.
DynamicAssembly

AssemblyBuilder

"I'm not encouraging you to write code you don't understand. That's what the Entity Framework Generator is for"

DynamicMetaObject


C# Expression Trees

Dynamic operator using Dynamic Language Runtime