DotNet::Services.GetStaticProperty Method

Syntax

dim Result as L = GetStaticProperty(FullyQualifiedPropertyName as C, OPTIONAL Assembly as DotNet::AssemblyReference = null_value(), PARAMS Args as A)

Arguments

FullyQualifiedPropertyNameCharacter

 

AssemblyDotNet::AssemblyReference

 

ArgsAny Type

 

Returns

ResultLogical

Returns .t. or .f. whether or not the operation succeeds. The DotNet::Services CallResult property will contain additional information about the error.

Description

Retrieves a static/class property value from an arbitrary .NET class.

GetStaticProperty() retrieves a static/class property value from an arbitrary .NET class without having to register the assembly or class using one of the functions above. The value retrieved is stored in the Data property of the CallResult member of the Services instance. If the assembly has not been loaded in the current process, the assembly will be loaded before the value is set.

Even though the addressability is lost, assemblies remain loaded in the Common Language Runtime (CLR), so the value will be retained across calls.

 Example

Getting the value of a static property from a registered (in this case system) assembly.

Dim PropertyName as C = "System::DateTime::Today"
Dim Services as DotNet::Services
 
If .not. Services.GetStaticProperty(PropertyName)
 UI_Msg_Box("Error getting property " + PropertyName, \
 Services.CallResult.Text)
Else
 UI_Msg_Box("Get property " + PropertyName + \
 " returned the following value", "" + \
 Services.CallResult.ResultDataValue)
End if

Additional Notes:

  1. .NET differentiates between a "field" and a "property". Fields are essentially class member variables that are made available. Properties are "smart variables" that have accessor methods (also called getters and setters) so that values can be checked when set or generated when read, or so that values can either be read only or write only. The syntax to set a.NET field or property is the same. Alpha Anywhere uses type information to determine whether the value is a field and sets or gets the appropriate element.

  2. If the field or property you are getting or setting is an array or (in the case of properties) has a setter that takes index or key values, these must be passed to GetStaticProperty as the third and consecutive arguments (Args).

  3. If you are setting a .NET field or array, be sure to account for the fact that .NET indexes arrays from zero by default. Xbasic syntax (val[2]) automatically accounts for this difference and subtracts one from your subscript. If you call a function to set or get a property, it isn't clear to Alpha Anywhere whether the index should be adjusted or not, so no change is made. You must convert one-based indexes to zero-based values.