IR
irwinrodriguez.dev
Back to docs

API Reference

Complete documentation of the FoxBridge class and the collection proxies it generates dynamically.

FoxBridge class

The only class you need to instantiate. All other objects are internally generated proxies.

Create the bridge and activate it before use
loBridge = NEWOBJECT("FoxBridge", "FoxBridge.prg")
IF !loBridge.Activate(lcJwt)      && obligatorio: sin esto no funciona nada
    ? loBridge.GetLastError()
    RETURN
ENDIF
Method / Property Returns Description
Activate(jwt) L (.T./.F.) Activates the license with the JWT your own code hands it. It is mandatory and enforced in the IDE and in the EXE alike: without activating, any call answers "FoxBridge is not activated". Returns .F. if the JWT is not valid and leaves the reason in GetLastError(); it does not raise a VFP ERROR.
Create(typeName [, p1..p10]) Proxy Instantiates a .NET type. typeName can be a simple name, a Qualified Assembly Name (with comma) or a generic type (List<String>).
Static(typeName) Proxy Returns a proxy to access static members of a type (methods, properties, class fields).
LoadAssembly(path) L (.T./.F.) Loads a .NET DLL into the execution context. Required before Create() with types from that DLL.
GetLastError() C Returns the last .NET error message. It is cleared at the start of each call and CONSUMED when you read it: a second read straight after comes back empty, so keep it in a variable if you need it twice.
TypeExists(typeName) L Checks if a type exists without throwing an exception. Useful for safe DLL detection.
GetObjectCount() N Number of live .NET objects in the heap. Useful for detecting memory leaks.
Version() C "FoxBridge Runtime 1.0.0 / Core …". This is how you check that the native DLL loaded and responds.
RuntimeVersion() · CoreVersion() C The two halves separately: the version of the VFP layer and that of the .NET engine.
SetProxyPath(path) Folder where the generated proxy classes are written. It must be called BEFORE the first Create().
SetDebug(.T./.F.) Turns on the internal call trace. It goes out through the debugger channel, so the published binaries (built in Release) print nothing: for diagnosis, use GetLastError().

Proxy objects (.NET instances)

Every object created with Create() or Static() is a FoxBridge proxy. These are the universal methods available on all proxies.

Method Description
MetodoNET([args]) Any public method of the underlying .NET type. FoxBridge resolves overloads automatically.
.Propiedad Reading any public property. If it returns an object, the result is another proxy.
.Propiedad = valor Writing to read/write properties.
GetHandle() Returns the internal handle (integer) of the .NET object. Useful to check if two proxies point to the same object.

List<T> and Array proxy

When Create() detects that the type is a list or array, it returns a proxy with this interface.

Method Description
Count()Number of elements in the collection. It is a method, with parentheses.
Item(n)The VALUE of the element at position n (1-based): string, number or .NULL. For objects, GetObject(n).
GetObject(n)The element as a proxy. This is the one to use when the collection holds .NET objects; Item(n) is for scalars.
Add(valor)Adds an element to the end.
Remove(valor)Removes the first occurrence of the value. Returns .T. if it was there.

Dictionary<K,V> proxy

When Create() detects that the type is a dictionary, it returns a proxy with this interface.

Method Description
Set(clave, valor)Sets or overwrites a key.
Get(clave)Returns the scalar value of the key, or .NULL. if what is there is a .NET null.
GetObject(clave)Returns the value as a proxy, for when the value is a .NET object.
ContainsKey(clave)Returns .T. if the key exists. The method is called ContainsKey; there is no Contains().
Remove(clave)Removes the key and its value. Returns .T. if it was there.

Error handling

FoxBridge propagates .NET exceptions as VFP errors. The recommended pattern is TRY/CATCH.

Catching a .NET type that does not exist with TRY/CATCH
TRY
    loObj = loBridge.Create("Tipo.Que.No.Existe")
    loObj.HacerAlgo()
CATCH TO loEx
    ? "Tipo de error:", loEx.ErrorNo
    ? "Mensaje:      ", loEx.Message   && contiene el mensaje de .NET
    ? "Ultimo error: ", loBridge.GetLastError()
ENDTRY
Remember to release proxies Each FoxBridge proxy holds a reference to an object in the .NET heap. Assigning = .NULL. releases that reference and invokes the .NET GC.

Back to examples: Examples ->