編譯成功取得 CompiledAssembly 後,反射掃描模組類型靜態方法並快取:
if (myAssembly != null) {
Type moduleType = myAssembly.GetType(nsName + "." + moduleName);
if (moduleType != null) {
MethodInfo[] methods = moduleType.GetMethods(
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
foreach (MethodInfo m in methods) {
ScriptMethodInfo info = new ScriptMethodInfo();
info.MethodName = m.Name;
info.MethodObject = m;
info.ModuleName = moduleType.Name;
info.ReturnType = m.ReturnType;
myScriptMethods.Add(info);
if (bolOutputDebug) Debug.WriteLine("Get vbs method \"" + m.Name + "\"");
}
bolResult = true;
}
}
private class ScriptMethodInfo {
public string ModuleName;
public string MethodName;
public MethodInfo MethodObject;
public Type ReturnType;
public Delegate MethodDelegate;
}
private ArrayList myScriptMethods = new ArrayList();
MethodInfo 與 Delegate 雙重參考,支援兩種調用路徑ReturnType 供未來型別檢查擴充mdlXVBAScriptEngine,命名空間 NameSpaceXVBAScriptEngine