1
Some day I'll do it too.
And I want to make with Roslyn.
You can create a base method return to get values from scripts:
And execute scripting looks like that:
- Console.WriteLine(CSharpScriptEngine.Execute("new ScriptedClass().HelloWorld"));
- Console.ReadKey();
Look to:
https://blog.jayway.com/2015/05/09/using-roslyn-to-build-a-simple-c-interactive-script-engine/
https://www.google.com.br/search?q=create+scriptings+with+roslyn&ie=&oe=
Suggestion: You 'll need take care about the code that your end user will put, could be dangerous.
Good look.
Accepted 0
Thanks to Jefferson for answer,
I have used this :
User selects .dll file from drop down list.
File is then loaded to DLL variable trough Assembly.LoadFile(File path) method, namespace System.Reflection.
Then get all types from DLL into array t.
Then create variable c as instance of t[0], that would be first class inside DLL.
This is according to demands of my program. If there are more than one classes inside DLL there is need to know which one is to be used, and adapt program accordingly.
Get wanted method from selected class by its name, in this case it is method Pack_Elements with many parameters, and one returning value type of DataGridView.
Invoke selected method.
In this case DataGridView Table_List is populated with returned values inside DataGridView from called method.
- if(External_Algorithms.Checked==true)
- {
-
- var DLL = Assembly.LoadFile(External_Algorithms_File_Paths[External_Algorithms_List.SelectedIndex]);
-
- Type [] t = DLL.GetTypes();
- var c = Activator.CreateInstance(t[0]);
- var method = t[0].GetMethod("Pack_Elements");
- Table_List = (DataGridView)method.Invoke(c, new object[{table_width*Multiply,
- table_height*Multiply,
- saw_blade_tickness,
- cleaning_left_table_edge*Multiply,
- cleaning_right_table_edge*Multiply,
- cleaning_up_table_edge*Multiply,
- cleaning_down_table_edge*Multiply,
- horizontal,
- vertical,
- Element_List_Copy,
- sort_by_area});
- }
This woks fine, but there is problem with security and possibility that user with its own error inside program code turns down the main application, so it seems that second option is better solution.
All the best,
Željko Peric
