Global methods like window object

Jan 6, 2013 at 9:10 PM


Sub importObject(context As JavascriptContext, objet As Object, name As String)
	For Each method As Reflection.MethodInfo In objeto.GetType().GetMethods
		If method.ToString() <> "Boolean Equals(System.Object)" And method.ToString() <> "Int32 GetHashCode()" And method.ToString() <> "System.Type GetType()" And method.ToString() <> "System.String ToString()" Then
			context.Run(method.Name & "=" & nombre & "." & method.Name)
			Threading.Thread.Sleep(1) 'to 100 max
End If Next End Sub




Class Window
	Sub alert(msg As String)
		MsgBox(msg, MsgBoxStyle.Information, "Javascript message")
	End Sub
End Class



Dim js As JavascriptContext
Dim window As Window

js = New JavascriptContext
window = New Window

js.SetParameter("window", window) 'declare the window object
importObject(js, window, "window") 'do global the window object

js.Run("alert('hello world')") 'test

Sorry for my less and bad english. I just try to help ;)