|
ParameterAttribute class
Namespace: CodeEffects.Rule.Attributes
Assembly: CodeEffects.Rule.dll
If applied to a parameter of a qualified method, marks it as a parameter of a rule action or an in-rule method. This parameter must be of source object type or any value type supported by Web Rule (qualified parameter).
Syntax
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
public sealed class ParameterAttribute : System.Attribute
Properties
-
ConstantValue Type: System.String
Gets or sets the constant value that Web Rule should pass to the method as a parameter when it evaluates the rule. Setting this property to any value signals Web Rule not to display this parameter on the UI when the rule author adds the in-rule method or action to the rule. If this is the only parameter, the in-rule method or action will appear in the UI as "parameterless", i.e. as a regular field.
-
DataSourceName
Type: System.String
Used only in rule action or in-rule method parameters that represent System.Int parameters of qualified .NET methods. Ignored for parameters of other types. Gets or sets the unique name of the Dynamic Menu Data Source declared by the SourceAttribute on the source object. If set, the rule author can only select the value from the menu of items supplied by the data source method.
-
DateTimeFormat Type: System.String
Used only with qualified parameters of date and time types. Ignored by parameters of other types. Gets or sets the date or time format of the qualified parameter. You can use standard C# date and time formatting. This property is not used during rule evaluation. This property is optional. The default date parameter value is "MMM dd, yyyy", and the default time parameter value is "hh:mm tt".
-
Description Type: System.String
Gets or sets the description of the parameter. Rule authors can see this description when they hover the mouse over the parameter element in the Rule Editor. The value of this property is ignored if RuleEditor.ShowDescriptionsOnMouseHover is set to False. It's not advisable to use this property in multilingual applications; instead, use culture-specific custom Source XML documents. This property is optional.
-
Max Type: System.Int64
Used only with qualified parameters of numeric and string types. Ignored by parameters of other types. For numeric parameters, gets or sets the maximum value that rule authors can enter manually. For string parameters, gets or sets the maximum length of the string that rule authors can type as the value. Used by Web Rule only in the UI, it has no effect on rule evaluation. This property is optional.
-
Min Type: System.Int64
Used only with qualified parameters of numeric type. Ignored by parameters of other types. Gets or sets the minimum value of the qualified parameter that rule authors can enter manually. Used by Web Rule only in the UI, it has no effect on rule evaluation. This property is optional.
-
ValueInputType Type: CodeEffects.Rule.Common.ValueInputType
Gets or sets the value indicating whether the qualified parameter should only be typed in manually, or it should only accept fields of the same type as a value, or both. For example, consider the in-rule method DoSomething("John"). The parameter "John" is a string that the rule author typed in. This is a value entered by tye "user", i.e. it's of type ValueInputType.User. The same in-rule method can be expressed as DoSomething(MiddleName). The parameter MiddleName is a field, so this parameter was selected by the rule author as a "field" item from the menu, i.e. it's of type ValueInputType.Fields. This property is optional. The default value is ValueInputType.All, which allows both User and Fields input types.
Notes
In the rule ...
If Get credit score( SSN ) is less than [640] then Decline( "Bad credit" )
... the Get credit score is an in-rule method, the "SSN" is its parameter and can be customized with the ParameterAttribute, the [640] is the value element that can be customized with the ReturnAttribute (i.e. the return value of in-rule method), the Decline is an action and "Bad credit" is the action's parameter that can also be customized with the ParameterAttribute class. See the source object topic for details on in-rule methods and actions.
In-rule methods and rule actions can have parameterless signatures or declare any number of qualified parameters. Parameters can be customized in a manner similar to fields but with fewer options.
Method parameters can also be marked as constant by setting the ConstantValue property to any value. This "hides" such parameters from rule authors, always passing the specified constant value to the method during rule evaluation. If a method contains only constant parameters or parameters of source type, such a method is displayed to rule authors as a rule field. For example, consider a fictitious source object and four overloads of the Action method, declared in some Helper class and referenced by the source object with ExternalActionAttribute:
using CodeEffects.Rule.Common;
using CodeEffects.Rule.Attributes;
namespace TestLibrary
{
[ExternalAction(typeof(Helper), "Action")]
public class DoerOfThings
{
[Field(Max = 30)]
public string Something { get; set; }
}
public class Helper
{
[Action("Action One")]
public void Action()
{
}
[Action("Action Two")]
public void Action(DoerOfThings source)
{
}
[Action("Action Three")]
public void Action(
[Parameter(ValueInputType.All, ConstantValue = "ABC")]
string text)
{
}
[Action("Action Four")]
public void Action(
[Parameter(ValueInputType.All, ConstantValue = "XYZ")]
string text,
[Parameter(ValueInputType.User)]
int number)
{
}
}
}
Action One takes no parameters; rule authors will see it as a field when the DoerOfThings is given to Web Rule control as its source object:
If Something is "test 1" then Action One ...
Action Two takes only one parameter of type DoerOfThings. This class is a source object for this rule. During rule evaluation Web Rule passes the instance of the source object to the action. This is a very powerful feature of Web Rule. See the source object topic for details on rule actions. Web Rule also displays the Action Two as a field - no need to bother rule authors with parameters unless it's necessary.
... else if Something is "test 2" then Action Two ...
Action Three takes one parameter of type System.String which is decorated as a constant parameter. Web Rule hides such parameters from rule authors as well, passing the constant value set by ParameterAttribute to the action during rule evaluation.
... else if Something is "test 3" then Action Three ...
Action Four takes two parameters: a constant string and a regular integer. Web Rule hides the constant parameter but displays the regular integer, asking the rule author for the input (notice the ValueInputType.User attribute). The value "XYZ" is passed to the Helper.Action method as its first parameter during rule evaluation.
... else Action Four([123])
|