wwDotNetBridge::CreateArray

Creates a new ComArray instance based on the .NET type you specify as a parameter.

ComArray is a wwDotnetBridge wrapper type that can be passed to InvokeMethod() or SetProperty() and is converted by wwDotNetBridge into the native array type that is stored in the Value property thus allow keeping the array entirely in .NET without having to be marshaled into FoxPro arrays.

This method has an overloaded parameter that either accepts an array instance from which to construct a ComArray instance, or a string of the element's full .NET type name (like System.Net.MailMessage).

o.CreateArray(lvArrayInstanceOrTypeName)

Parameters

lvArrayInstanceOrElementTypeName
Pass either an instance of a .NET array, or a string that is the full name of the element's type. You can also pass nothing or NULL to receive an empty ComArray into which you can load an Enumerable or other Array Type.

For Element Type Strings: For the element name pass the full .NET typename for the array elements to be created. Each element of the array will be of this type. Use System.Object if you need to pass mixed types for each element rather than a single type for each element.

Remarks

ComArray objects are converted into .NET arrays only if you use indirect access via InvokeMethod or SetProperty, not direct object calls.

Example

loBridge = CREATEOBJECT("wwDotNetBridge")

loService = CREATEOBJECT("Sample.MyService")

*** Create an instance of the array with the 
*** specific type of the elements
LOCAL loArr as Westwind.WebConnection.ComArray
loArr = loBridge.CreateArray("System.Object")

*** Add Items
loArr.AddItem("New Item")
loArr.AddItem(10)

*** Create a new Array Item (based on array type)
loCust = loArr.CreateItem()
loCust.Company = "West Wind"
loCust.Entered = DateTime()

*** Add the object to the array
loArr.AddItem(loCust)

*** Now call a method that takes the array as a parameter
loBridge.InvokeMethod(loService,"PassArray",loArr)

*** Retrieve an array as a ComArray
loArr = loBridge.GetProperty(loService,"Persons")

*** Updates actual .NET item Instance
loArr.Item(0).Company = "New Name"

loCust = loArr.CreateItem()
loCust.Company = "New Customer"
loCust.Enterd = DateTime()

loArr.AddItem(loCust)

*** Assign to a property of an object
loBridge.SetProperty(loObject2,"Persons",loArr)

See also:

Class wwDotNetBridge | Accessing Arrays, Lists and Dictionaries with ComArray

© West Wind Technologies, 1996-2024 • Updated: 10/21/22
Comment or report problem with topic