Returns an item by index or key from a List or Dictionary collection without any type conversion for FoxPro.
This function may fail if the array item type is not compatible with FoxPro, typically with an Function argument value, type or count is invalid error. This may be useful for some types like
char
orGuid
that are returned differently for fixups.
This works on:
- Array (int)
- Array List (int)
- IList (int)
- ICollection (any type)
- HashSet (any type)
- IDictionary (key type) (or int for index)
You can specify either an integer for list types or any type for collections. int keys are 0 based.
For dictionaries
int
values retrieve the item at the specified indexed location, unless the Dictionary key type isint
.If the key type is
int
(or a FoxPro number) theint
key is treated as a key value, rather than an index. For all other key types, the key is treated as an index.
public object ItemRaw(object indexOrKey)
Return Value
matching item or null
Parameters
indexOrKey
int 0 based key for lists or any value for collections/dicionaries
Exceptions
**System.ArgumentException**Invalid index or key type
Remarks
Dictionaries can use an
int
value to return a value out of the collection by its index **if the key type is not ofSystem.Int
. This is a special case and allows you to iterate a dictionary which otherwise would not be possible.
Example
*** Access generic list through indirect access through Proxy and get ComArray
loList = loBridge.InvokeMethod(loNet,"GetGenericList")
? loBridge.ToString(loList) && System.Collections.Generic.List...
? loList.Count && 2
*** Grab an item by index
loCust = loList.Item(0)
? loCust.Company
*** Iterate the list
FOR lnX = 0 TO loList.Count -1
loItem = lolist.Item(lnX)
? loItem.Company
ENDFOR
*** Retrieve a generic dictionary
loList = loBridge.InvokeMethod(loNet,"GetDictionary")
? loList.Count && 2
*** Return Item by Key
loCust = loList.Item("Item1") && Retrieve item by Key
? loCust.Company
*** This works as long as the key type is not int
loCust = loList.Item(0) && Retrieve item by Index
? loCust.Company
*** This allows iterating a dictionary
FOR lnX = 0 TO loList.Count -1
loItem = lolist.Item(lnX)
? loItem.Company
ENDFOR
See also:
Class ComArray© West Wind Technologies, 1996-2024 • Updated: 04/17/24
Comment or report problem with topic