Dashboard > BOO > ... > Duck Typing > without duck typing
without duck typing Log In | Sign Up   View a printable version of the current page.

Added by Rodrigo B. de Oliveira , last edited by Rodrigo B. de Oliveira on Oct 25, 2004
Labels: 
(None)

import System.Threading
import System.Reflection

def CreateInstance(progid):
	type = System.Type.GetTypeFromProgID(progid)	
	return type()	
	
def SetProperty(target, name, value):
	target.GetType().InvokeMember(name, BindingFlags.SetProperty, null, target, (value,))
	
def GetProperty(target, name):
	return target.GetType().InvokeMember(name, BindingFlags.GetProperty, null, target, null)
	
def Invoke(target, name, arg):
	return target.GetType().InvokeMember(name, BindingFlags.InvokeMethod, null, target, (arg,))

ie = CreateInstance("InternetExplorer.Application")
SetProperty(ie, "Visible", true)
Invoke(ie, "Navigate2", "http://www.go-mono.com/monologue/")

Thread.Sleep(50ms) while GetProperty(ie, "Busy")

document = GetProperty(ie, "Document")
print("${GetProperty(document, 'title')} is ${GetProperty(document, 'fileSize')} bytes long.")

Alternatively, one could use the tlbimp utility included with the .net framework sdk to generate an interop assembly from the Internet Explorer type library.

Site running on a free Atlassian Confluence Open Source Project License granted to The Codehaus. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.2 Build:#919 Nov 26, 2007) - Bug/feature request - Contact Administrators