How do you use .NET SDK for setting an object to a list (IRISLIST<OBJECT)>?
Hello,
I'm using the .Net C# IRIS client and trying to create a HS.Data.OIDMap object which contains a $LIST property (.IdentityTypes). I am able to create the object using the .NET client, however when trying to create and assign the list object I get a "List cannot contain of type IrisObject".
Documentation for HS.Data.OIDMap https://docs.intersystems.com/irisforhealth20243/csp/documatic/%25CSP.Documatic.cls?LIBRARY=HSSYS&PRIVATE=1&CLASSNAME=HS.Data.OIDMap
My question is two fold
- How to do you set a object property that is a list that needs to container other IrisObjects?
- How do you create a list of IrisObjects? The documentation for .Net Iris list says it cannot contain and Object or IrisOject (https://docs.intersystems.com/irisforhealthlatest/csp/docbook/DocBook.UI.Page.cls?KEY=BNETNAT_refapi#BNETNAT_refapi_iris-list)
The high level steps for this are
- Create the Iris Connection (Works)
- Create the HS.Data.OIDMap object (Works)
- Open and store HS.Data.OIDType of a certain type (ex: "Device") (Works)
- Set the IdentityTypes property to a new list containing the HS.Data.OIDType retrieved previously. (NOT WORKING) Error the a IrisList cannot contain a instance of IrisObject
Example Code (C#):
//Create IRIS Instance to Iris4Health Server
IRIS iris = IRIS.CreateIRIS(conn);
IRISObject OidMap = (IRISObject)iris.ClassMethodObject("HS.Data.OIDMap","%New");
//Set some props (omitted for clarity)
//Get the Device type from the OIDType objects and store it (Getting the device OID Type)
//this returns a IrisObject
var oType = iris.ClassMethodObject("HS.Data.OIDType","%OpenId","Device");
//Create a new list and store the OIDTypes in this list
IRISList newList = new IRISList();
newList.Add(oType); // Generates ERROR: 'Invalid type: IRISObject'
//try and set the property IdentityTypes of the OIDMAP object
OidMap.Set("IdentityTypes",newList);
Comments
It looks like the IdentityTypes property is not a $list, but a list collection. You can read more about those here: https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cl…
To use list collections in .NET IRIS Native, you treat them like any other IRISObject.
Your sample code would now look something like this
IRIS iris = IRIS.CreateIRIS(conn);
IRISObject OidMap = (IRISObject)iris.ClassMethodObject("HS.Data.OIDMap","%New");
var oType = iris.ClassMethodObject("HS.Data.OIDType","%OpenId","Device");
// new code
IRISObject newList = (IRISObject)iris.ClassMethodObject("%ListOfDataTypes", "%New");
newList.InvokeVoid("Insert", oType);
OidMap.Set("IdentityTypes",newList);Also, you don't need to instantiate the list directly, and can get it by accessing the existing property instead
IRISObject list = (IRISObject)OidMap.GetObject("IdentityTypes")
list.InvokeVoid("Insert",oType);Thanks, I'll try this when I get a moment