Class ComArray

ComArray is a special wwDotnetBridge wrapper for .NET arrays that facilitates accessing .NET arrays and allows easy access, adding, editing and removing of array elements through the high level array interface on the ComArray instance.

It manages .NET arrays without marshalling them into FoxPro and so losing their .NET object status. By default FoxPro marshals .NET arrays to FoxPro arrays, but once you do you can no longer manipulate the array easily. ComArray allows you to easily receive the array and manipulate using simple object based collection syntax. ComArray is the preferred mechanism to manipulate .NET arrays from FoxPro.

Instances can be created with:

  • loBridge.CreateArray(<.NET typename>)
  • loBridge.GetProperty(loInst,"ArrayProperty") where ArrayProperty is an Array
  • loBridge.InvokeMethod(loInst,"someMethod") where it returns an Array

The ComArray class is a .NET helper class that wraps .NET arrays in a COM friendly way for FoxPro. The class contains an internal Instance property of the array and exposes a simple interface to access, add, remove and clear all elements. ComArray can hold simple values like System.String, complex objects, or generic objects (System.Object) which essentially allow for variable type arrays.

ComArrays are automatically returned from calls to InvokeMethod() that return an array and from array properties accessed with GetProperty()/GetPropertyEx(). You can also pass a ComArray to a .NET method that expects an array if you use InvokeMethod() and use the ComArray as a parameter for the array or for calls to SetProperty().

System.Object
  Westwind.WebConnection.ComArray
public class ComArray : object

Class Members

MemberDescription

Constructor

Constructor

AddItem

Adds an item to the internal array instance.

Array should exist before adding items.

public bool AddItem(object item);

AssignFrom

public bool AssignFrom(object baseInstance,     string arrayPropertyName);

AssignTo

Assigns this ComArray's array instance to the specified array property.

o.ComArray.AssignTo(baseInstance, arrayPropertyName)

Clear

Clears out the array contents

public bool Clear();

CreateArray

Creates a new array instance with size number of items pre-set. Elements are unassigned but array is dimensioned.

Use SetItem() to assign values to each array element

public bool CreateArray(string arrayTypeName,     int size);

CreateEmptyArray

Creates a .NET array instance with 0 items on this ComArray instance

public bool CreateEmptyArray(string arrayTypeName);

CreateItem

Creates an instance of the array's member type without actually adding it to the array. This is useful to more easily create members without having to specify the full type signature each time.

Assumes that the array exists already so that the item type can be inferred.

public object CreateItem();

FromEnumerable

oComArray.FromEnumerable(loEnumerable)

Item

Returns an item from the array by its index number. Note that .NET arrays are 0 based!

public object Item(int index);

RemoveItem

Removes an item from the array.

public bool RemoveItem(int index);

SetItem

Assigns a value to an array element that already exists.

public bool SetItem(int index,     object value);

Count

Returns the length of the .NET array contained in Instance

Instance

The actual array instance returned as an object. This instance is set and passed to and from .NET calls made with InvokeMethod and explicit property assignments with Set/GetProperty.

Length

Returns the length of the array

Example

*** Manually create a ComArray for a .NET element type (string array here)
loStringArray = loBridge.CreateArray("System.String")
loStringArray.Add("New String Value")
loStringArray.Add("Another String Value")

*** Pass ComArray instead of string[] array parameter
loBridge.InvokeMethod(loInst,"PassArray",loStringArray)

*** Set to a property
loBridge.SetProperty(loInst,"StringArrayProperty",loStringArray)

*** Retrieve an array as a ComArray
loArr = loBridge.InvokeMethod(loInst,"GetPersonsArray");

*** Retrieve a property as a ComArray
loArr = loBridge.GetProperty(loInst,"Persons")

Requirements

Namespace: Westwind.WebConnection
Assembly: wwdotnetbridge.dll

© West Wind Technologies, 1996-2022 • Updated: 11/25/21
Comment or report problem with topic