c# - Expression.DebugInfo How Do I Tag Expressions? -
so know expression.debuginfo used for, , have debug expression created, how tag other expressions debug info? here's i'm trying basic test:
using system; using system.collections.generic; using system.linq; using system.text; using system.linq.expressions; using system.reflection; namespace expressiondebugtest { class program { static void main(string[] args) { var asm = appdomain.currentdomain.definedynamicassembly(new assemblyname("foo"), system.reflection.emit.assemblybuilderaccess.runandsave); var mod = asm.definedynamicmodule("mymod", true); var type = mod.definetype("baz", typeattributes.public); var meth = type.definemethod("go", methodattributes.public | methodattributes.static); var sdi = expression.symboldocument("testdebug.txt"); var di = expression.debuginfo(sdi, 2, 2, 2, 12); var exp = expression.divide(expression.constant(2), expression.subtract(expression.constant(4), expression.constant(4))); var block = expression.block(di, exp); expression.lambda(block, new parameterexpression[0]).compiletomethod(meth); var newtype = type.createtype(); asm.save("tmp.dll"); newtype.getmethod("go").invoke(null, new object[0]); //meth.invoke(null, new object[0]); //lambda.dynamicinvoke(new object[0]); console.writeline(" "); } } }
i know debug info works compiled methods that's why i'm generating assembly on fly. when code causes "divide zero" error, it's not showing my "testdebug.txt" file
so seems missing debug info generator. code needed added:
var gen = debuginfogenerator.createpdbgenerator(); expression.lambda(block, new parameterexpression[0]).compiletomethod(meth,gen);
it works charm now!
Comments
Post a Comment