CLR Extender Reference

Basic Concepts

Description »

To fully use the functionality of .NET Extender it is recommended to understand a little terminology related to the .NET Framework.

Assembly

An assembly is an EXE file, DLL file or a combination of several files; which usually contain Public Types (classes, structures) that you can use in your programs.

Although there are assemblies which only have resources inside, the most useful assemblies are the ones with public types which expose functionality that you consume in your programs.

You usually make an assembly accessible using SetCLRClassLibrary or by creating an object directly from the assembly through CLRNewObject.

Types (Enums, Structures and Classes)

These are Data Structures which are exposed by the .NET Framework.

  • Classes. These are the most used feature of the .NET Framework, a class maps to the VFP Class you already know, with some differences:
    • A class usually has a long name, its full name, which you need in order to create an object instance using CLRCreateObject or CLRNewObject.
    • While in VFP you need a Class Instance to invoke its methods. That is, you need to use CreateObject to get an instance before using any method; in .NET you can invoke static (shared in VB) methods which are methods tied to the class instead of a particular instance. You typically use CLRInvokeStaticMethod or for better performance, you get a reference to the class using CLRGetTypeReference and then call these methods.
    • Classes have constructors. A constructor is a special method that is called when the Instance is constructed, it is somewhat similar to the Init event which runs every time a instance is constructed, but it IS NOT the same. If a Class only exposes Constructors with arguments you can´t create an Instance without passing arguments to CLRCreateObject or CLRNewObject. This is very important when using these functions.
  • Structures. These are basically the same as classes except they can't inherit from other structures. Usually are used like small classes. In .NET Extender you use them as if they are classes.
  • Enums. These are numeric constants which are referenced in other .NET Types. An enum is basically a collection of numeric constants that you typically use to improve the legibility of your code, so instead of using cryptic numbers, you use the more easy to remember names.

    In .NET Extender you can use integer numbers or strings with the name of the enum member wherever you need to reference an enum member. You can use the Assembly Browser to import the enum like a group of #DEFINES constants.

Namespaces

A NameSpace is a way to group related types into a coherent name hierarchy. For example the System::Windows::Forms namespace groups a lot of types related to Forms and Controls. Inside a NameSpace every Type name has to be unique.

A NameSpace also helps Programmers to avoid name collision. For example in the .NET Framework there are several classes named Control, but because these classes are contained into different NameSpaces there are not name collisions.

For example, the Checkbox type contained in the System::Windows::Forms NameSpace is referenced from .NET Extender using its FullName: System::Windows::Forms::CheckBox.

Overloaded methods or Method overload

In VFP, given a method name you can only define one method with that name. This is in contrast with the .NET Framework where you can have several methods with the same name differing between them in the number of parameters and / or parameter types.

.NET Extender for VFP lets you access these overloaded methods like you would expect, using the common name. Because of the potential of overload, the arguments you pass to the method are also used to choose the best overload to call.

For example:

Give this class in the VFP language as of VFPCompiler for .NET with the overloaded method MethodA

DEFINE CLASS MyClass as System::Object

PROCEDURE MethodA

LPARAMETERS aValue as Integer

RETURN aValue

 

PROCEDURE MethodA

LPARAMETERS aValue as String

RETURN LEN(aString)

ENDDEFINE

 

oMyClass = CLRCreateObject("MyClass")

oMyClass.MethodA(5) && Calls the integer version Returns 5

oMyClass.Method("eTecnologia") && Calls the string version returns 11

Example »

Give this class in the VFP language as of VFPCompiler for .NET with the overloaded method MethodA

DEFINE CLASS MyClass as System::Object

PROCEDURE MethodA

LPARAMETERS aValue as Integer

RETURN aValue

 

PROCEDURE MethodA

LPARAMETERS aValue as String

RETURN LEN(aString)

ENDDEFINE

 

oMyClass = CLRCreateObject("MyClass")

oMyClass.MethodA(5) && Calls the integer version Returns 5

oMyClass.Method("eTecnologia") && Calls the string version returns 11

Remarks »

 


Send comments about this topic to eTecnologia.net.