JScript Programming Tips
Below are a few JScript programming tips that you may find useful while developing a scripting project in XMLSpy Scripting Editor.
Out parameters
Out parameters from methods of the.NET Framework require special variables in JScript. For example:
var dictionary = CLR.Create("System.Collections.Generic.Dictionary<System.String,System.String>"); |
Integer arguments
.NET Methods that require integer arguments should not be called directly with JScript number objects which are floating point values. For example, instead of:
var objCustomColor = CLR.Static("System.Drawing.Color").FromArgb(128,128,128); |
use:
var objCustomColor = CLR.Static("System.Drawing.Color").FromArgb(Math.floor(128),Math.floor(128),Math.floor(128)); |
Iterating .NET collections
To iterate .NET collections, the JScript Enumerator as well as the .NET iterator technologies can be used, for example:
// iterate using the JScript iterator |
.NET templates
.NET templates can be instantiated as shown below:
var coll = CLR.Create( "System.Collections.Generic.List<System.String>" ); |
or
CLR.Import( "System" ); |
.NET enumeration values
.NET enumeration values are accessed as shown below:
var enumValStretch = CLR.Static( "System.Windows.Forms.ImageLayout" ).Stretch; |
Enumeration literals
The enumeration literals from the XMLSpy API can be accessed as shown below (there is no need to know their numerical value).
objExportXMIFileDlg.XMIType = eXMI21ForUML23; |