Writing Value Providers
Retired Content |
---|
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. |
Value providers derive from the abstract ValueProvider class. The class has three methods, used to call a value provider:
- OnBeginRecipe. This method is called at the beginning of recipe execution.
- OnBeforeActions. This method is called right before actions are executed.
- OnArgumentChanged. This method is called when an argument changes value.
The methods receive the current value of the argument, set the new value of the argument, and return True if the new value should be put into argument dictionary. The following code example shows the DateNow value provider.
namespace $PackageNamespace$.ValueProviders
{
public class DateNowValueProvider : ValueProvider
{
public override bool OnBeginRecipe(object currentValue, out object newValue)
{
if(currentValue!=null)
{
// Do not assign a new value, and return false to flag that
// we don't want the current value to be changed.
newValue = null;
return false;
}
newValue = DateTime.Now;
return true;
}
}
}
Note
Value Providers should always check if there is an existing value in an argument and only change the value if appropriate. They should not change values by default as the values can be provided either by the user, as the template is unfolded or by another recipe that spawned the current recipe.
For information about how value providers are called, see Gathering Arguments.
See also
Developing Recipes | Specifying Command Bars | Specifying Bound References | Specifying Unbound References | The AddMainClass Recipe