DotNetObject.GetProperty

Query the value of a property

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 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.