private object Parse(string text, bool expression) { const string varName = "x___"; EXCEPINFO exceptionInfo; object result; _engine.SetScriptState(ScriptState.Connected); var flags = ScriptText.None; if (expression) { flags |= ScriptText.IsExpression; } try { // immediate expression computation seems to work only for 64-bit // so hack something for 32-bit... if (_parse32 != null) { if (expression) { // should work for jscript & vbscript at least... text = varName + "=" + text; } _parse32.ParseScriptText(text, null, null, null, IntPtr.Zero, 0, flags, out result, out exceptionInfo); } else { _parse64.ParseScriptText(text, null, null, null, IntPtr.Zero, 0, flags, out result, out exceptionInfo); } } catch { if (_site._lastException != null) { throw _site._lastException; } throw; } IntPtr dispatch; if (expression) { // continue out 32-bit hack... if (_parse32 != null) { _engine.GetScriptDispatch(null, out dispatch); var dp = Marshal.GetObjectForIUnknown(dispatch); try { return(dp.GetType().InvokeMember(varName, BindingFlags.GetProperty, null, dp, null)); } catch { if (_site._lastException != null) { throw _site._lastException; } throw; } } return(result); } _engine.GetScriptDispatch(null, out dispatch); var parsed = new ParsedScript(this, dispatch); return(parsed); }
private object Parse(string text, bool expression) { const string varName = "x___"; EXCEPINFO exceptionInfo; object result; _engine.SetScriptState(ScriptState.Connected); var flags = ScriptText.None; if (expression) { flags |= ScriptText.IsExpression; } try { // immediate expression computation seems to work only for 64-bit // so hack something for 32-bit... if (_parse32 != null) { if (expression) { // should work for jscript & vbscript at least... text = varName + "=" + text; } _parse32.ParseScriptText(text, null, null, null, IntPtr.Zero, 0, flags, out result, out exceptionInfo); } else { _parse64.ParseScriptText(text, null, null, null, IntPtr.Zero, 0, flags, out result, out exceptionInfo); } } catch { if (_site._lastException != null) throw _site._lastException; throw; } IntPtr dispatch; if (expression) { // continue out 32-bit hack... if (_parse32 != null) { _engine.GetScriptDispatch(null, out dispatch); var dp = Marshal.GetObjectForIUnknown(dispatch); try { return dp.GetType().InvokeMember(varName, BindingFlags.GetProperty, null, dp, null); } catch { if (_site._lastException != null) throw _site._lastException; throw; } } return result; } _engine.GetScriptDispatch(null, out dispatch); var parsed = new ParsedScript(this, dispatch); return parsed; }