In my C # application, I have an object with, for example. the properties of Colorand Size, and its are populated from db values.
Then I have a design application that allows the user to add C # / VB code (an entire class with certain methods), which may or may not use / change the values from the properties of the object
When the application starts the class, a codeprovider will be created in memory from the line created by the design application, and a special method called (reflection) at runtime
How can I allow a dynamic code method to refer to my object (not static and populated from user data) so that if a user adds code, for example:
if(TheObject.Color == "Blue")
TheObject.Width="150";
I can make it work if I pass the object to a dynamic class as an input parameter:
....
ocResults = oCodeProvider,CompileAssemblyFromSource(oCParams, userCode);
oAssy = oCResults.CompiledAssembly;
oExecInstance = oAssy.CreateInstance("userClass");
oType = oExecInstance.GetType();
oType.GetMethod("OnLoad", new Type[] { typeof(myObj) });
but you cannot determine where to place the object so that the dynamic code can refer to it (the dynamic code will be generated and executed for each user, but they must refer to the object created for their session.
User code should be easy to write and no need to get a link from, for example, for. static Dictionary<String,Object>(link via user code AppDic["UserName"].Color), and then remove it from the dictionary when executing dynamic code.
The user code should simply be: TheObject.Color(for example, the static method, since the user code does not have to create an instance, the code that creates the dynamic code has already filled in the property values. The user should be able to modify / read);
- ?