We are currently implementing an application with scripting enabled using the DLR. One goal is to write a single code base for Silverlight and WPF. Most pieces work great. However, what we are missing is something like Microsoft.Scripting.Actions.IDynamicObject (from DLR SDK on codeplex) or System.Dynamic.IDynamicMetaObjectProvider (from .NET 4).
Here is what we try to achieve:
- Develop a class in C# with some built-in properties
- Extend the class (e.g. add properties) using user-configurable metadata DURING RUNTIME (to be exact: the scripts will be used to modify metadata)
- Access instances of the class from within python scripts; the scripts have to have access to both built-in AND dynamically added properties
We have a working solution for WPF 3.5 and 4.0. In Silverlight we did not find a proper interface with which we can achieve what we have to build.
We have already thought (and implemented) a workaround using dynamically generated types (based on ILGenerator.Emit). In this workaround we create derived classes on the fly based on metadata. This works nice with Silverlight (special feature: This way Data Binding works!). However, in our case metadata can change every now and than which results in a large number of unused dynamically generated types because once created we cannot get rid of the types any more (we do not want to create them in a separate AppDomain, too much overhead). Because of this a dynamic solution like on the full client would be preferred.
It would be great if someone could point me to a possible solution. Even if you don't have one and you are sure that what we want is not possible in Silverlight 3, please drop me a line. In this case we can stop researching.