|
Section: .NET Extender for VFP
.NET Extender for VFP
Legal Disclaimer
Samples:
.NET Extender Samples
Printing Sample
Sample MenuStrip
CLR Extender Reference:
Installation
Basic ConceptsDeploying .NET Extender apps
Walkthrough - Hosting .Net Controls
Assembly Browser
CLRBindEvent
CLRUnBindEvent
CLRCreateObject Function
CLRGetTypeReference
CLRInvokeStaticMethod
CLRNewObject Function
SetCLRClassLibrary
UI WebServices Importer
List Of Functions
|
CLR Extender Reference
CLRGetTypeReference Function
Description »
Gets a reference to the Class Type and allows to invoke Static (C#) or Shared (VB) methods, Get static properties or Set Static Properties. A Static member is a Class Member (Method, field, property) which IS NOT associated with any particular object instance.
CLRGetTypeReference(cType [, cAssembly] )
Parameters
- cType
- Specifies the name of the Type on which to invoke the method. Include the type's FullName (i.e. System::IO::Directory).
Note:
If you don't include the optional parameter cAssembly then cType has to be accessible from one of the assemblies loaded with SetCLRClassLibrary.
- [, cAssembly ]
- Specifies the .NET assembly where the cType 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)
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 as an Assembly in the Global Assembly Cache the .NET Framework loads the assembly from the Cache. It does not matter if you included an absolute path, it still loads it from the GAC.
Return Value
An object reference to the cType Type. This returned object works like a proxy to the class allowing you to Invoke Static Methods, Set Static Fields or Properties or Get Static Fields or Properties.
The returned object reference IS NOT a instance of cType, thus it can't be used to access instance members. In fact, not instance of cType are created at all.
Example »
The following example gets references to System::IO.Directory and to System::IO::File to retrieve several information of the files in the HOME() directory.
LOCAL oTypeDirectory, oTypeFile, aFiles, i
oTypeDirectory = CLRGetTypeReference("system::io::Directory")
oTypeFile = CLRGetTypeReference("system::io::file")
aFiles = oTypeDirectory.GetFiles(HOME())
FOR i = 1 TO ALEN(aFiles)
? aFiles(m.i)
? "Created on ", oTypeFile.GetCreationTime(aFiles(m.i)).ToString()
? "Last accessed on", oTypeFile.GetLastAccessTime(aFiles(m.i)).ToString()
ENDFOR
aDrives = oTypeDirectory.GetLogicalDrives()
FOR i = 1 TO ALEN(aDrives)
? aDrives(m.i)
ENDFOR
Remarks »
CLRGetTypeReference is the preferred way to use static members of a type. It is faster and more general than CLRInvokeStaticMethod.
* Gets a reference to the class System::IO::Directory
* this is a special .NET class, which only has static methods, so you
* can't create and instance of it
oTypeDirectory = CLRGetTypeReference("system.io.directory","mscorlib.dll")
* Invokes GetDirectories a Static Method, of course
aDirectories = oTypeDirectory.GetDirectories(HOME())
aFiles = oTypeDirectory.GetFiles(HOME())
? aDirectories(1)
? aFiles(1)
- OR -
* Gets a reference to the class System::IO::File
* this is a class which only has static methods
oTypeFile = CLRGetTypeReference("system.io.File","mscorlib.dll")
* Reads all the lines of the file into an array string, think of FILETOSTR and ALINES together
arrLines = oTypeFile.ReadAllLines(HOME()+"Tools\eTecnologiaNETExtender\Samples\io\writestream.prg")
? ALEN(arrLines)
Send comments about this topic to eTecnologia.net.
|
|