Altova MapForce 2023 Basic Edition

An instance method has a .NET object passed to it as the first argument of the method call. This .NET object typically would be created by using an extension function (for example a constructor call) or a stylesheet parameter/variable. An XSLT example of this kind would be:

 

<xsl:stylesheet version="2.0"

   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

   xmlns:xs="http://www.w3.org/2001/XMLSchema"

   xmlns:fn="http://www.w3.org/2005/xpath-functions">

   <xsl:output method="xml" omit-xml-declaration="yes"/>

   <xsl:template match="/">

      <xsl:variable name="releasedate"

         select="date:new(2008, 4, 29)"

         xmlns:date="clitype:System.DateTime"/>

      <doc>

         <date>

            <xsl:value-of select="date:ToString(date:new(2008, 4, 29))"

               xmlns:date="clitype:System.DateTime"/>

         </date>

         <date>

            <xsl:value-of select="date:ToString(\$releasedate)"

               xmlns:date="clitype:System.DateTime"/>

         </date>

      </doc>

   </xsl:template>

</xsl:stylesheet>

 

                 

In the example above, a System.DateTime constructor (new(2008, 4, 29)) is used to create a .NET object of type System.DateTime. This object is created twice, once as the value of the variable releasedate, a second time as the first and only argument of the System.DateTime.ToString() method. The instance method System.DateTime.ToString() is called twice, both times with the System.DateTime constructor (new(2008, 4, 29)) as its first and only argument. In one of these instances, the variable releasedate is used to get the .NET object.

 

 

Instance methods and instance fields

The difference between an instance method and an instance field is theoretical. In an instance method, a .NET object is directly passed as an argument; in an instance field, a parameter or variable is passed instead—though the parameter or variable may itself contain a .NET object. For example, in the example above, the variable releasedate contains a .NET object, and it is this variable that is passed as the argument of ToString() in the second date element constructor. Therefore, the ToString() instance in the first date element is an instance method while the second is considered to be an instance field. The result produced in both instances, however, is the same.

 

© 2017-2023 Altova GmbH