CLR Extender Reference
CLRNewObject Function
Description »
Creates a new .NET Object from the specified library
CLRNewObject(cClassName, cAssembly, [, eParameter1 , eParameter2 , ...])
Parameters
- cClassName
- The name of the class to create. Use the class fully qualified name in this format: Namespace1::Namespace2::ClassName.
Note:
You can use the Assembly Browser to see the Full Qualified Names of the types.
- cAssembly
- Specifies the .NET assembly where the cClassName resides. You can include a Full Path, Relative path and for assemblies available in the .NET Framework, just the assembly name.
Note:
Always include the assembly extension. (i.e. MyAssembly.dll)
- [, eParameter1 , eParameter2 , ...]
- The parameters to pass to the instance's constructor. See the class documentation for info about the parameters.
Note:
Some .NET classes only exposes constructors with parameters. Be sure to include the right number and type of parameters.
Return Value
An object reference. If it can't create the object, fails and an error is raised with additional information shown
Example »
The following example creates a file in the temporary directory and writes to it:
LOCAL oStream, cFile, cText
cFile = SYS(2023)+"\file.txt"
* Creates the object using the constructor: FileStream(file as string, mode as FileMode)
oStream = CLRNewObject("SYSTEM::IO::FileStream","mscorlib.dll",m.cFile,4)
cText = CREATEBINARY("This is a test") && to transfer it like an byte array
oStream.Write(m.cText,0,LEN(m.cText))
? oStream.Length
oStream.Close()
MODIFY FILE (m.cFile)
Remarks »
This function is modeled after the VFP's NEWOBJECT.
To create or open an existing file:
oStream = CLRNewObject("SYSTEM::IO::FileStream","mscorlib.dll","c:\temp\file.txt",4)
Or to open an existing file:-
oStream = CLRNewObject("SYSTEM::IO::FileStream","mscorlib.dll","c:\temp\file.txt",3)
Send
comments about this topic to eTecnologia.net.