DotNet::Services.SetStaticProperty Method

IN THIS PAGE

Syntax

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

Arguments

FullyQualifiedPropertyNameCharacter

ValueAny Type

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

Sets a static/class property value in an arbitrary .NET class.

Discussion

SetStaticProperty() sets a static/class property value in an arbitrary .NET class without having to register the assembly or class using one of the functions above. 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

Setting the value of a static property in a private assembly.

Dim Services as DotNet::Services
Dim Assembly as DotNet::AssemblyReference
Dim PropertyName as C = "Alpha5DotNet::Environment::ProductVersion"
Dim Value as N = 12

Assy.FileName = "c:\dev\Bin\Alpha5DotNet.dll"
If .not. Services.SetStaticProperty(PropertyName, Value, Assembly)
    UI_Msg_Box( "Error setting property " + PropertyName, Services.CallResult.Text)
Else
    UI_Msg_Box( "Set property result: " + Services.CallResult.Text)
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 SetStaticProperty as the fourth 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.