Programming Points

www.altova.com Imprimer cette rubrique Page précédente Un niveau supérieur Page suivante

Accueil >  Programmers' Reference > Scripting Editor >

Programming Points

The following programming points should be noted:

 

All namespaces and types of the following .NET assemblies can be accessed in the Microsoft .NET Framework per default:

 

 System

 System.Data

 System.Design

 System.Drawing

 System.Windows.Forms

 System.XML

 

Additional assemblies can be added to the scripting project via the project's context menu, or dynamically (at runtime) in the source code by using CLR.LoadAssembly.

 

 

 

 

Out-parameters from methods of the XMLSpy API require special variables in JScript. Given below are some examples.

 

                 // use JScript method to access out-parameters

 var strError = new Array(1);

 var nErrorPos = new Array(1);

 var objBadData = new Array(1);

 bOK = objDoc.IsValid(strError,nErrorPos,objBadData);END

 

 

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 >" );

 dictionary.Add("1", "A");

 dictionary.Add("2", "B");

 

 // use JScript method to access out-parameters

 var strOut = new Array(1);

 if ( dictionary.TryGetValue("1", strOut) // TryGetValue will set the out parameter

         alert( strOut[0] ); // use out parameter

 

 

.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 ) );

 

 

To iterate .NET collections the JScript Enumerator as well as the .NET iterator technologies can be used:

 

For example:

 // iterate using the JScript iterator

 var itr = new Enumerator( coll );

 for ( ; !itr.atEnd(); itr.moveNext() )

         alert( itr.item() );

 

 // iterate using the .NET iterator

 var itrNET = coll.GetEnumerator();

 while( itrNET.MoveNext() )

         alert( itrNET.Current );

 

.NET templates can be instantiated as shown below:

 

var coll = CLR.Create( "System.Collections.Generic.List<System.String>" );

 

or

 

 CLR.Import( "System" );

 CLR.Import( "System.Collections.Generic" );

 var dictionary = CLR.Create( "Dictionary< String, Dictionary< String, String > >" );

 

.NET Enum values are accessed as shown below:

 var enumValStretch = CLR.Static( "System.Windows.Forms.ImageLayout" ).Stretch;

 

Enumeration literals, as defined in the Altova type libraries, can now be used instead of numerical values.

 

 objExportXMIFileDlg.XMIType = eXMI21ForUML23;

 


© 2019 Altova GmbH