Skip to main content
Version: 4.4.0

Code expression examples

Assigning a setting attribute value to property

The following example illustrates how to assign a setting value (ErrorHandlingComponent) of string type to an IntegerValue. Because the IntegerValue is compatible with string type, no conversion is needed.

Context.System.Settings.Lookup("All").Groups.Get(Of iCore.LocalSystem.Settings._iCPS_SystemCommon).ErrorHandlingComponent

Assigning to a property of activity complex type

When assigning to a property of activity complex type, the result of all elements of the activity complex type (including any existing code expression) is always converted to string before it is assigned to the property. Hence, the type compatibility is not as important as for other types.

Assigning a custom formatted value to a property

Some types support different string representation specified by a format string. The following example illustrates a DateTime value in accordance with the format assigned to a property of StringValue type:

//Will return <hours>:<minutes>:<seconds>
DateTime.UtcNow.ToString("hh:mm:ss")

For more information about the custom format string, please refer to the documentation for that specific type.

Looking up a Node filename

Context.System.Nodes.Get(v2Args.EventNodeId).NodeFileName

Getting separated data

The below example shows how code expressions can be used to split up the string "Good¤bye".

v2Args.EventParameters.Split('¤')[0] => Good
v2Args.EventParameters.Split('¤')[1] => bye

Creating a lambda expression to filter an IEnumerable

The following example shows how an IEnumerable can be filtered with a lambda expression. In the example, the Errors property of a variable of type IAS2Message is filtered. The property is of type IEnumerable\<IAS2MessageError>. The return value from Where is an IEnumerable\<IAS2MessageError> that contains errors where the DispositionModifier is Error.

as2Message.Errors.Where(Function(error) error.DispositionModifier = AS2DispositionModifier.Error)

Retrieving a certificate from a Windows store

This example shows how to retrieve a certificate from a Windows store. The example uses the following variables:

  • location – contains an integer which represents how the Windows store is accessed. For example, 1 implies that the store is accessed as CurrentUser. The integer value needs to be converted to the enum type CertificateStoreLocation, hence the CType function is used.
  • storename – contains a string with the name of the store to retrieve the certificate from. For example, “My” implies that that the certificate is retrieved from the store My, also known as Personal.
  • issuer – contains a string with the issuer's distinguished name, or part of it. For example, “CN=test123, OU=department2”
  • serial – contains a string with the serial number in a hex string format. For example, “23B423DD21014D”

The values of the variables can be fetched from a Setting. In the example, the requireExactNameMatch argument is set to False which indicates that part of the issuer's distinguished name can be left out. For example, if the issuer's complete distinguished name is “CN=test123, OU=department2, O=company” it would be sufficient to use “CN=test123” provided there are no other issuers with the same common name (CN).

iCore.Public.Crypto.X509Certificates.Certificate.GetFirstInSystemStoreByIssuerAndSerialNumber( CType(location, iCore.Public.Crypto.X509Certificates.CertificateStoreLocation), storename, issuer, serial, requireExactNameMatch:= False)