Property Editor Basics Specifying Editors
  • Updated on 09 Dec 2013
  • 1 minute to read
  • Print
  • Dark
    Light

Property Editor Basics Specifying Editors

  • Print
  • Dark
    Light

Overview

You can change how property editors display in the tool. For example, a property editor that appears as a text box may be converted to a drop down menu. You can make these changes by decorating properties with property editor attributes.


Example

For this example we will write a step that has a property called Level for which you want to allow users to select from three levels. To do this, you would need to decorate your Level property 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:
2017-02-10_151204.png

After decorating, the property will show up in the designer looking like this:
2017-02-10_144225.png

The example above showed how to specify values by providing the attribute with a string array. You can also create another property which supplies the values to this attribute. This is useful when you want 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 how the property which is specified about might look:

 [PropertyHidden]
private string[] AvailableLevels
{
    get { return new string[] { "Level 1", "Level 2", "Level 3" }; }
    set { }
}

The above example shows how to set a property editor on a property. You can also set a property editor on an input parameter to a simple method step. To do this, you simple place the editor attribute you want to use directly before the parameter name you want to apply it to. Notice how the [PasswordTextAttribute] is applied to the string password input parameter below.

 [AutoRegisterMethodsOnClass(true, "Sample Steps", RegisterForAgents = true)]
public class SampleInputPropertyEditorSteps
{
    public void SampleInputPropertyEditorStep(string username, [PasswordTextAttribute] string password)
    {
        //do something
    }
}

Doing this will cause the password editor to show up when selecting a constant mapping type.

Was this article helpful?