vb.net - end-user defined code - how to use existing classes and objects from the ExecutingAssembly -
i have winform similar op has in how load internal class in end-user compiled code ? (advanced) have textbox source of end-user code, , compiled on fly when hit button.
here parts of code (where copied how load internal class in end-user compiled code ? (advanced) :
imports system imports system.codedom.compiler imports system.reflection imports system.text public class form1 private sub executeb_click(byval sender system.object, byval e system.eventargs) handles executeb.click dim code string = me.codetoexec.text dim compilerresult compilerresults compilerresult = compile(code) end sub public function compile(byval code string) compilerresults dim codeprovider new vbcodeprovider dim codecompiler system.codedom.compiler.codedomprovider = codedomprovider.createprovider("visualbasic") dim parameters new system.codedom.compiler.compilerparameters parameters.generateexecutable = false parameters.referencedassemblies.add("system.dll") parameters.referencedassemblies.add("system.windows.forms.dll") parameters.referencedassemblies.add("microsoft.visualbasic.dll") dim compilerresult compilerresults = codecompiler.compileassemblyfromsource(parameters, code) if compilerresult.errors.haserrors compiletb.clear() = 0 compilerresult.errors.count - 1 compiletb.appendtext(compilerresult.errors(i).errortext & vbcrlf) next return nothing else return compilerresult end if end function end class
my controls are: codetoexec textbox user puts custom code, compiletb textbox errors listed, , executeb button. there other classes , object in program, , here 1 of classes want use:
public class exceptioncriteria private _criterianame string public property criterianame string criterianame = _criterianame end set(value string) _criterianame = value end set end property private _ruleset list(of string) public property ruleset list(of string) ruleset = _ruleset end set(value list(of string)) _ruleset = value end set end property private _serializationfilepath string public property serializationfilepath string serializationfilepath = _serializationfilepath end set(value string) _serializationfilepath = value end set end property public sub addrule(newrule string) if isnothing(_ruleset) _ruleset = new list(of string) end if _ruleset.add(newrule) end sub end class
and here 1 of members want use/set in form1 class:
public comparisondate date = #2/20/2015#
my problem is, want access/modify objects, members, properties in executing assembly , create new objects based on custom classes there. how can this?
i have bumped answer, lacked was
parameters.referencedassemblies.add(assembly.getexecutingassembly().location)
then needed make procedures , members shared. hope helps newbies me happen have same problem , pass page.
Comments
Post a Comment