- 20 Aug 2021
- 1 Minute to read
- Print
- DarkLight
SDK: Property Editor Basics Specifying Editors
- Updated on 20 Aug 2021
- 1 Minute to read
- Print
- DarkLight
Overview
Users can change how property editors are displayed. For example, a property editor that appears as a text box may be converted to a drop-down menu. These changes can be done by decorating properties with property editor attributes.
Example
In the following example, a step will be created that has a property called Level which will allow users to select from three levels.
Create a Level property and decorate it with the following attribute:
[SelectStringEditor(new string[] {"Level 1", "Level 2", "Level 3"}, SelectStringEditorType.DropdownList)]
If the Level property was not decorated with this attribute, it would show up in the designer looking like this:
After decorating, the property will show up in the designer looking like this:
Using Another Property to Supply Values
The example above showed how to specify values by providing the attribute with a string array. Another property can be created that supplies the values to this attribute. This is useful to dynamically fetch the possible values at design time. Below is an example showing how this can be done.
[SelectStringEditor("AvailableLevels", SelectStringEditorType.DropdownList)]
public string Level
Here is an example of that property :
[PropertyHidden]
private string[] AvailableLevels
{
get { return new string[] { "Level 1", "Level 2", "Level 3" }; }
set { };
}
Setting Property on Input Parameter
The above example shows how to set a property editor on a property. A user can also set a property editor on an input parameter to a simple method step. Place the desired editor attribute directly before the parameter name. In the example below, the [PasswordTextAttribute] is applied to the string password input parameter below. Doing this will cause the password editor to show up when selecting a constant mapping type.
[AutoRegisterMethodsOnClass(true, "Sample Steps", RegisterForAgents = true)]
public class SampleInputPropertyEditorSteps
{
public void SampleInputPropertyEditorStep(string username, [PasswordTextAttribute] string password)
{
//do something
}
}