I’m a huge fan or runtime code generation. I think it solves a lot of common problems in modern applications. However, the .NET implementation of runtime code gen, a.k.a. the CodeDOM, is viciously difficult to learn and use. I think that’s holding many people back from implementing good solutions using runtime codegen.
For example, it takes all this
CodeConditionStatement ifArrayNotNull = new CodeConditionStatement(
new CodeBinaryOperatorExpression(propertyRef,
CodeBinaryOperatorType.IdentityInequality,
new CodePrimitiveExpression(null))
);
CodeMethodInvokeExpression convertExpr = new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(typeof(Convert)),"ToBase64String",
new CodeExpression[] { new CodeCastExpression(typeof(byte[]),propertyRef)}
ifArrayNotNull.TrueStatements.Add(convertExpr);
to make this
if(myObject.Property != null)
{
Convert.ToBase64String(myObject.Property);
}
Not only is it a lot more code using the CodeDOM, but it’s certainly not the kind of code that you can just pick up and understand.
There must be an easier way. Refly helps a bunch, but last time I tried it I found it to be incomplete. It’s certainly a step in the right direction. It’s certainly a model that’s much easier to understand. I wonder if, in the end, it’s too limiting? There may be a good reason for the complexity of the CodeDOM. Or there may not be.
Powered by: newtelligence dasBlog 1.9.6264.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2008, Patrick Cauldwell
E-mail