The script.net itself does not implement the ability to invoke script libraries. If you put a bunch of already defined functions in a script file as a script library, you just need to make a little change to call the script library.
First, create an XML document that specifically stores which libraries the script will call, structured as follows
<?xml version= "1.0" encoding= "Utf-8"?><libmapping> <mainscript scriptname= "" > < Libscript libfilename= ""/> </MainScript></LibMapping>
For example:
<?xml version= "1.0" encoding= "Utf-8"?><libmapping> <mainscript scriptname= "Script1.txt" > <libscript libfilename= "Lib1.txt"/> <libscript libfilename= "Lib3.txt"/> </mainscript > <mainscript scriptname= "Script2.txt" > <libscript libfilename= "Lib1.txt"/> < Libscript libfilename= "Lib2.txt"/> </MainScript></LibMapping>
Then parse the XML before executing the script, find out the script library it needs to call through the ScriptName property, read the script library file with the IO operation and add it to the script string, the code is as follows
string script = String. Empty; Script + = File.readalltext ("script1.txt") + "\ n";//Read the scripting file string libscript = string. Empty; Parse XML file XmlDocument xmldoc = new XmlDocument (); Xmldoc.load ("Libmapping.xml"); XmlNode Mainnode = Xmldoc.selectsinglenode (string. Format ("//libmapping/mainscript[@scriptName = ' {0} ']", "script1.txt")); if (Mainnode! = null) { XmlNodeList liblist = mainnode.childnodes; Read Script library foreach (XmlNode node in liblist) { String fileName = node. attributes["Libfilename"]. Value; Libscript + = File.readalltext (fileName) + "\ n"; } } script+= Libscript;
Script s = script.compile (script);
The disadvantage of this is that debugging is inconvenient, if the script code error or there is an exception, simple string concatenation will make the error code of the number of lines may be incorrect, find the error code when there is difficulty, I hope that there is a better way to solve the hero.
Script.net Implementing a Script library