Scripting:Importing assemblies

From TSWiki

Jump to: navigation, search

WebCoder scripting allows you to import additional assemblies for use within your scripts. This is done with the clr object, using one of the Add methods:

  • AddReference
  • AddReferenceByName
  • AddReferenceByPartialName
  • AddReferenceToFile
  • AddReferenceToFileAndPath

It's usually easiest to use the AddReferenceByPartialName, since it only requires you to remember the simple name of an assembly, instead of the complete name, including version, culture and public key token.

[edit] Example

clr.AddReferenceByPartialName("System.Windows.Forms")

You may load several assemblies, either by duplicating the above example line, or by specifying several names in the call:

clr.AddReferenceByPartialName("System.Windows.Forms", "System.Xml")

[edit] Importing classes

When adding a reference to an assembly, you should import one or several classes from it. This is done with the from and import keywords, like this:

clr.AddReferenceByPartialName("System.Windows.Forms")
from System.Windows.Forms import MessageBox

You may import several classes from the same namespace like this:

clr.AddReferenceByPartialName("System.Windows.Forms")
from System.Windows.Forms import MessageBox, Form

Or you may import every single class in the namespace using the * operator, like this:

clr.AddReferenceByPartialName("System.Windows.Forms")
from System.Windows.Forms import *
Personal tools