.NET Framework Developer Center >
.NET Development Forums
>
Microsoft SQL Server Modeling
>
Oslo and DLR in .Net 4.0
Oslo and DLR in .Net 4.0
- Is it possible to use the Dynamic Language Runtime and Expression Trees from .Net 4.0 to help build a runtime for Oslo output?
Does this make sense?
Is there an example of this?
Answers
- Yeah it's definitely possible. I have done this for a project of mine already, but I didn't do it from the repository just from straight M Graph output. It's definitely not simple though I will tell you. Doing it from the repository would probably be about the same except that you're getting your metadata from somewhere else.Here is my sample:http://metasharp.codeplex.com/SourceControl/changeset/view/32489#398880 // dynamic pipelinehttp://metasharp.codeplex.com/SourceControl/changeset/view/32489#398922 // dynamic pipeline unit testshttp://metasharp.codeplex.com/SourceControl/changeset/view/32489#398885 // template for dynamically transforming a Song DSL into a lambda.The gist is, use a Visitor pattern to visit your graph and build up an expression tree then compile it into a delegate. The thing I made lets you compile textual DSLs into linq expressions using a T4 like language for doing transforms. Or you can do the language itself. such as:var result = pipeline.Eval<int>("x + y", new { x = 3, y = 7 });Assert.AreEqual(21, result);So it's definitely possible! The only limitation is that you cannot create new Types using purely linq expressions. You can create new types using DynamicAssembly but then you have to emit your own IL, you cannot use the linq expressions to create method bodies for DynamicMethods (at least I couldn't figure it out). Which also means you cannot access "this" or members of this from within a lambda but you can make implicit references by adding parameters and constants. There are still lots of cool things you can do though.
- Marked As Answer byDonBaechtel Monday, November 02, 2009 3:25 PM
- Proposed As Answer byKraig BrockschmidtMSFT, ModeratorThursday, October 22, 2009 2:58 AM
All Replies
- Yeah it's definitely possible. I have done this for a project of mine already, but I didn't do it from the repository just from straight M Graph output. It's definitely not simple though I will tell you. Doing it from the repository would probably be about the same except that you're getting your metadata from somewhere else.Here is my sample:http://metasharp.codeplex.com/SourceControl/changeset/view/32489#398880 // dynamic pipelinehttp://metasharp.codeplex.com/SourceControl/changeset/view/32489#398922 // dynamic pipeline unit testshttp://metasharp.codeplex.com/SourceControl/changeset/view/32489#398885 // template for dynamically transforming a Song DSL into a lambda.The gist is, use a Visitor pattern to visit your graph and build up an expression tree then compile it into a delegate. The thing I made lets you compile textual DSLs into linq expressions using a T4 like language for doing transforms. Or you can do the language itself. such as:var result = pipeline.Eval<int>("x + y", new { x = 3, y = 7 });Assert.AreEqual(21, result);So it's definitely possible! The only limitation is that you cannot create new Types using purely linq expressions. You can create new types using DynamicAssembly but then you have to emit your own IL, you cannot use the linq expressions to create method bodies for DynamicMethods (at least I couldn't figure it out). Which also means you cannot access "this" or members of this from within a lambda but you can make implicit references by adding parameters and constants. There are still lots of cool things you can do though.
- Marked As Answer byDonBaechtel Monday, November 02, 2009 3:25 PM
- Proposed As Answer byKraig BrockschmidtMSFT, ModeratorThursday, October 22, 2009 2:58 AM


