DotNetObject.GetProperty
WSupported on Windows
|
|
|
|
object.GetProperty(propertyname, value)
or
value = object.GetProperty(propertyname)
Arguments
object
An object returned by the DotNetObject constructor, the DotNetAssembly constructor, or some other property or method that returns an object.
propertyname
The name of the property to query.
value
Returned with the coerced value for the property.
Discussion
If object is an object returned from the DotNetAssembly constructor, only static properties can be accessed using the namespace.class.property form of propertyname. Propertyname must be a public or public static property defined for the specified object, and a get method must exist for it so that it is not write-only. Otherwise, an $ERR_MISSMETH error occurs.
If a property 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_MISSMETH error occurs.
If the first GetProperty syntax above is used (that is, the value is returned in a writable parameter), the value of the property will be coerced to the type of the passed argument as follows:
- If the argument is of type string, the property value is converted to a Synergy string, using Object.ToString if it is not a .NET string.
- If the argument is of type integer, the property value is converted to integer if possible. If not, an $ERR_INVCAST error occurs.
- If the argument is of type decimal, the property value is converted to a string and passed to the Synergy store subsystem for conversion to decimal. If a conversion error occurs, an $ERR_DIGIT error occurs.
- If the argument is of type DotNetObject or System.Object, the value of the property is wrapped in a DotNetObject and returned. If the property value is null, ^NULL is returned instead.
- If the argument is of type decimal or integer, truncation may occur if the argument is not large enough (for example, if a UInt32 property is returned into an i4 variable).
If the second GetProperty syntax is used, the value is coerced following the rules in the Objects Returned for .NET Types table, and then the coerced type is boxed as a System.Object if it is not already an object type.
Struct members can only be accessed after returning an instance of the struct using DotNetObject.GetProperty or DotNetObject.GetField, and then using DotNetObject.GetField on that returned instance to access its members.
Examples
The example below retrieves the static property System.DateTime.Now by casting asm to a DotNetObject, as well as casting the result of GetProperty to a DotNetObject from an @* type.
obj = (DotNetObject)((DotNetObject)asm).GetProperty("System.DateTime.Now")
The example below gets the value of the Hour property and returns it in itmp.
obj.GetProperty("Hour", itmp)
The following example does the same thing as the previous example, except that it unboxes int on its way into itmp.
itmp = (int)GetProperty("Hour")
See Sample programs for examples in the context of a complete program.