Thursday, February 7, 2008

LinFu.DynamicObject and Dynamic Object Models

I've been playing around with LinFu.DynamicObject and I've discovered a way to implement a dynamic typing system that can be changed at runtime. That means that with LinFu.DynamicObject, you can assign it to a particular DynamicType instance and any DynamicObjects that depend on that same instance will actually change their methods and properties at runtime to match that particular DynamicType!

Adaptive Object Models, anyone? :)

Dynamic Method Dispatch is one thing that LinFu can do very well, and pretty soon, you'll be able to reconfigure an entire object model in memory without having to recompile the application.

Suffice to say, things are going to get interesting with LinFu as the series of articles progresses.

Stay tuned!

3 comments:

  1. Hi Philip,

    Looking forward to the follow-up on this post. I'm just learning about dynamic approaches in C#. I recently posted a question/model for Generalized Algebraic Data Types on Channel9 here:

    http://channel9.msdn.com/ShowPost.aspx?PostID=386812

    Would definitely like to hear your feedback on whether this is a useful approach (esp. my second, more detailed implementation). The idea is to use runtime compilation of Expression trees to keep strongly typed computation but avoid IL-based dynamic code.

    ReplyDelete
  2. Hi David,

    Using LINQ expression trees to solve the extensibility problem in your case certainly has its uses, but in my opinion, working with LINQ expression trees tend to leave you with code that might be just as difficult to read as IL.

    What your approach seems to be using LINQ trees as a degenerate abstract syntax tree to ultimately compile itself to IL at runtime, and that might not be a useful approach if the expression tree code become difficult to read or maintain.

    The only benefit that I see with this approach is the type safety that it affords. You can only do so much to shield yourself from directly emitting the IL yourself, but you have to be careful because the expression tree code can be just as complicated as directly dynamically generating the IL.

    Caveat Emptor.

    ReplyDelete
  3. Thanks for the comments, Philip! In my case, type safety is key, as I'm building a generic library for novice users that I hope can be agnostic of the underlying structure.

    I plan on using only a few basic types/operations but I can see your point re: complexity. I look forward to C# 4.0...based on Ander's Lang.NET talk it sounds like a lot more of these constructs will be baked into the language.

    ReplyDelete

Ratings by outbrain