
1163
DEVELOPING
COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
Las
t
upda
te
d 8/5/2010
Disabling automatic conversion of complex .NET data
You can disable automatic conversion of .NET
System.Collections.Hashtable
,
System.Collections.ArrayList
or S
ystem.Data.DataTable
objects to the corresponding ColdFusion structure,
array, or query objects. You could want to disable the conversion under the following circumstances:
•
If a collection or DataTable returned by a .NET method is large and you only want a small subset of the data. If auto
conversion is enabled, ColdFusion creates a data structure with all the object’s fields. Creating the structure could
take significant time and resources, because ColdFusion must invoke .NET methods internally to get each of the
fields. You can disable the automatic conversion and retrieve the fields or data from .NET objects like any other
objects.
•
If you invoke a .NET method that returns a complex variable, and then pass the variable to another .NET method
as argument. If automatic conversion is enabled, you cannot pass the Hashtable object from the first method
directly to the second method.
To disable automatic conversion, set the JVM coldfusion.dotnet.disableautoconversion system property to true. For
example, in a ColdFusion stand-alone server, or if you use JRun as your J2EE server, include the following setting in
the JVM.config file:
-Dcoldfusion.dotnet.disableautoconversion=true
Manually converting complex .NET objects
Use the
DotNetToCFType
function to convert a
System.Collections.Hashtable
,
System.Collections.ArrayList
or S
ystem.Data.DataTable
object to a ColdFusion structure, array, or query
respectively when either of the following circumstances are true:
•
You have set the coldfusion.dotnet.disableautoconversion system property to true.
•
Automatic conversion is enabled, you created the complex .NET object by using the
createObject
function or
cfobject
tag, and you want to convert this object into the corresponding ColdFusion representation.
For an example of using the function, see DotNetToCFType in the
CFML Reference
.
Using .NET objects
.NET fields and return values with class types are available in ColdFusion as .NET objects. You can use the object’s
methods to access object data and make it available to ColdFusion using supported data types.
The following example gets information about a system’s drives. It calls the System.IO.DriveInfo.GetDrives() method
to get an array of System.IO.DriveInfo objects, one per drive. It then calls the object methods to get specific
information about the drives, and displays the information. The example uses a
cfdump
tag to simplify the code.
Note:
The System.IO.DriveInfo is not included in the .NET 1.x framework. It is included in .NET 2.0 and later
frameworks. For information on determining the .NET framework, see “
Determining and changing the .NET version
” on
page
1170.