困扰了好久了。c#反汇编回来的程序报了2个错误,
this.msc.add_Error(new DScriptControlSource_ErrorEventHandler(OnError));
this.msc.add_Timeout(new DScriptControlSource_TimeoutEventHandler(OnTimeout));
错误 1 “MSScriptControl.DScriptControlSource_Event.Error.add”: 无法显式调用运算符或访问器
完整代码如下
using MSScriptControl;
using System;
using System.Runtime.InteropServices;
using System.Threading;
public class ScriptEngine : IDisposable
{
public ScriptControl msc;
public event RunErrorHandler RunError;
public event RunTimeoutHandler RunTimeout;
public ScriptEngine() : this(ScriptLanguage.VBscript)
{
}
public ScriptEngine(ScriptLanguage language)
{
this.msc = new ScriptControlClass();
this.msc.UseSafeSubset = true;
this.msc.Language = language.ToString();
this.msc.add_Error(new DScriptControlSource_ErrorEventHandler(OnError));
this.msc.add_Timeout(new DScriptControlSource_TimeoutEventHandler(OnTimeout));
}
public void Dispose()
{
Marshal.ReleaseComObject(this.msc);
}
public object Eval(string expression, string codeBody)
{
this.msc.AddCode(codeBody);
return this.msc.Eval(expression);
}
public object Eval(ScriptLanguage language, string expression, string codeBody)
{
if (this.Language != language)
{
this.Language = language;
}
return this.Eval(expression, codeBody);
}
private void OnError()
{
if (this.RunError != null)
{
this.RunError();
}
}
private void OnTimeout()
{
if (this.RunTimeout != null)
{
this.RunTimeout();
}
}
public void Reset()
{
this.msc.Reset();
}
public object Run(string mainFunctionName, object[] parameters, string codeBody)
{
this.msc.AddCode(codeBody);
return this.msc.Run(mainFunctionName, ref parameters);
}
public object Run(ScriptLanguage language, string mainFunctionName, object[] parameters, string codeBody)
{
if (this.Language != language)
{
this.Language = language;
}
return this.Run(mainFunctionName, parameters, codeBody);
}
public bool AllowUI
{
get
{
return this.msc.AllowUI;
}
set
{
this.msc.AllowUI = value;
}
}
public ScriptLanguage Language
{
get
{
return (ScriptLanguage) Enum.Parse(typeof(ScriptLanguage), this.msc.Language, false);
}
set
{
this.msc.Language = value.ToString();
}
}
public int Timeout
{
get
{
return 0;
}
}
public bool UseSafeSubset
{
get
{
return this.msc.UseSafeSubset;
}
set
{
this.msc.UseSafeSubset = true;
}
}
}