Read/Write C# Properties and Indexers with IronPython

June 1, 2020

This topic is designed to provide examples of how to use C# libraries in IronPython executing in SoftPro Select. While the examples are valid for all C# uses, the objects used may be unfamiliar to many.

TLDR

In C#, properties typically hide class variables and allow the developer to validate user inputs. It also allows developers to allow reading but not writing (or vice-versa) for variables.

Examples

The Order object holds all the information about the order and is usually accessed by Python through properties and methods. The manner used to obtain the Order depends on where you put the Python code – Custom Order Rule, Automation process, Visibility condition or other. For the purposes of this topic, we will not care and simply assume that you have it in a Python variable named “Order”.

We can use the Select Field Code Browser (FCB) to see the Order properties. Be aware that FCB does not provide an exhaustive list of all properties. For instance, the FCB displays the property Number (of type string).

number = Order.Number                   # i.e. "ID19040011"

numBuyers = Order.Buyers.Count          # i.e. 2
firstBuyer = args.Context.Buyers[0]     # Get the first buyer
secondBuyer = args.Context.Buyers[1]    # Get the second buyer

We can set other properties by writing to the order model.

Order.Project = "Raleigh NC Townhome"
Order.Status = OrderStatus.Completed

Indexers

.. More to come…