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.

loBridge = NEWOBJECT("FoxBridge", "FoxBridge.prg")
Method / Property Returns Description
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. Cleared automatically after each successful call.
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.
Ping() C ("Pong") Verifies the native DLL is loaded and responding. Use at startup for diagnostics.
SetDebug(.T./.F.) Enables/disables detailed logging of native DLL calls (visible in DebugView).

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.
Item(n)Element at position n (1-based). Returns scalar or proxy depending on type.
GetObject(n)Like Item(n) but guarantees returning a proxy even if the element is a scalar. Use when the element is a .NET object.
Add(valor)Adds an element to the end.
Remove(valor)Removes the first occurrence of the value.

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.
GetObject(clave)Returns the value as a proxy (when the value is a .NET object).
Contains(clave)Returns .T. if the key exists.
Remove(clave)Removes the key and its value.

Error handling

FoxBridge propagates .NET exceptions as VFP errors. The recommended pattern is 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 ->