logo WinWrap®
November 25, 2017

Dynamic Object Creation

WinWrap® Basic scripts can create dynamic .NET objects.

Use CDynamic to create dynamic objects from a

  • Structure: A dynamic object containing all the instance fields and readable properties of the structure.
  • Array: A dynamic object containing all the values in the array (one dimension only).
  • Dictionary: A dynamic object containing all the keys as fields assigned the dictionary values.

Dynamic objects sometimes work better with advanced .NET APIs like JSON conversion classes.

The CDynamic function creates a dynamic .NET object from an expression.

'#Language "WWB.NET" Sub Main Dim dict As New System.Collections.Generic.Dictionary(Of String, Object) dict.Add("Field1", 1) dict.Add("Field2", "two") Dim dict2 As New System.Collections.Generic.Dictionary(Of String, Object) dict2.Add("SubField1", "subfield-one") dict.Add("Field3", CDynamic(dict2)) Dim dyn As Object = CDynamic(dict) Debug.Print dyn.Field1 ' 1 Debug.Print dyn.Field2 ' "two" Debug.Print dyn.Field3.SubField1 ' "subfield-one" End Sub

The example above shows how using the CDynamic function can create a dynamic .NET object from a dictionary.

Copyright Polar Engineering, Inc.