CLR Extender Reference
SetCLRClassLibrary Function
Description »
Add cAssembly to the list of assemblies to be searched for classes, when CLRCreateObject is called, or makes cAssembly the only assembly searched for class creation.
SetCLRClassLibrary(cAssembly [, lAdditive])
Parameters
- cAssembly
- Specifies the name of the assembly to add to the list of Assemblies.
Note:
You can include a full path with cAssembly or a relative path. For assemblies included with the .NET Framework, you can just pass the assembly name (i.e. "system.dll").
- lAdditive
- If true adds the assembly to the list, otherwise if makes the cAssembly the ONLY assembly searched when creating classes.
Return Value
Logical. True if the cAssembly was added to the list, otherwise false and an error is raised
Example »
The following example adds system.xml.dll to the list of assemblies searched. It then creates a system::xml::Document and loads the Document from a string.
LOCAL oXMLDocument
= SetCLRClassLibrary("system.xml.dll", .T.) && adds system.xml.dll to the list of assemblies to search
oXMLDocument = CLRCreateObject("system::xml::xmlDocument")
oXMLDocument.LoadXML('<root><item text="one" /><item text="two" /><item text="three" /></root>')
* Displays 1, the XMLDocument has one top node <root>
? oXMLDocument.ChildNodes.Count
* In .net collections are zero-based
* Displays 3 the child count of root
? oXMLDocument.ChildNodes.Item(0).ChildNodes.Count
? oXMLDocument.InnerXML
cFile = GETFILE("xml","Save oXMLDocument as")
IF NOT EMPTY(m.cFile)
oXMLDocument.Save(m.cFile)
MODIFY FILE (m.cFile)
ENDIF
Remarks »
Use this function to make available all the types in an assembly. The order in which the assemblies are added is important, because it searches in that order, from first to last added.
Note:
If you don't include a path with cAssembly, the .NET framework tries to load the assembly from the Global Assembly Cache first, then from the current directory of the Executable calling SetCLRClassLibrary.
If the assembly has the same Name and Public Key has an Assembly in the Global Assembly Cache the .NET Framework loads the assembly from the Cache. It does not matter you included a path, it still loads it from the GAC.
* makes system.dll the only assembly searched
* If other assemblies were in the list they are removed
= SetCLRClassLibrary("system.dll")
* or
= SetCLRClassLibrary("system.dll", .F.)
- OR -
SetCLRClassLibrary("system.xml.dll", .T.) && adds system.xml.dll to the list of assemblies to search
Send
comments about this topic to eTecnologia.net.