DotNetObject.SetField

Set the value of a field on an instance

WSupported on Windows

 

 

 

object.SetField(fieldname, value)

Arguments

object

An object returned by the DotNetAssembly constructor, the DotNetObject constructor, or some other property or method that returns an object.

fieldname

The name of the field to set.

value

The new value for the field.

Discussion

Fieldname must be a public or public static field defined for the specified object; otherwise, an $ERR_MISSFLD error occurs. If a field is defined more than once using different value types, the default binder will be used to attempt to locate the best fit for the parameter passed. If no match is found, an $ERR_MISSFLD error occurs.

If a value type is passed for the value argument, the system attempts to convert value from a Synergy/DE type to a .NET type using the same rules as for DotNetObject.Call. If an object is passed for the value argument, value must be either ^NULL (to indicate a null object) or an object returned by the DotNetObject constructor, DotNetObject.Call, DotNetObject.GetField, or DotNetObject.Get. Otherwise, an $ERR_INVCAST error occurs.

If a structfield member is to be set, the object will be a structfield returned from DotNetObject.GetProperty or DotNetObject.GetField. Structs are boxed objects (copies), and once the members have been updated with DotNetObject.SetField, the struct must be copied back to the original field or property location with DotNetObject.SetProperty or DotNetObject.SetField using the boxed struct returned from the original DotNetObject.GetProperty or DotNetObject.GetField.

If object is an object returned from the DotNetAssembly constructor, only static fields can be accessed using the namespace.class.field form of fieldname.

Examples

The example below sets the value of an instance field.

obj.SetField("instanceField", "fieldValue")

The example below sets the value of a static field.

asmObj.SetField("namespace.classname.StaticField", "fieldValue")