ExternalActionAttribute Class
Assembly: CodeEffects.Rule.Common.dll
Namespace: CodeEffects.Rule.Common.Attributes
Summary
IMPORTANT Generic methods with generic params cannot be used in Source XML as in-rule methods or rule actions. Use plain .Net class(es) if your source object declares generic methods.
When applied to a source object, this attribute references an external qualified public method to be used as a rule action. To qualify, the method must be public
, static or instance, return System.Void
and either be parameterless or declare only parameters of the source object type or of value types supported by Code Effects.
Syntax
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
public class ExternalActionAttribute : System.Attribute,
CodeEffects.Rule.Common.Attributes.IExternalAttribute,
CodeEffects.Rule.Common.Attributes.ISortable
Properties
Assembly
Type: System.String
Gets the full name of the assembly that contains the class declaring the action method. You can obtain this name by executing Assembly.GetAssembly(classType).FullName
. This property is required if the Type
property is not specified.
Method
Type: System.String
Gets the name of the method declared outside the source object that Rule Editor uses as a rule action. This property is required.
ParamTypesToMatch
Type: System.Type[]
Gets or sets an array of System.Type
objects that represent the parameter types matching the signature of the external method to be used as a rule action. This property can be used to select a specific overload of an external method.
SortOrder
Type: System.Int16
Gets or sets the sort order in which the rule action method appears in the action menu of the Rule Area. This property is optional. The default value is 0
.
Type
Type: System.Type
Gets the type of the class that declares the external action method. This property is required if the Assembly
and TypeName
properties are not specified.
TypeName
Type: System.String
Gets the full name of the type that declares the external action method. You can obtain this name by executing typeof(ClassName).FullName
. This property is required if the Type
property is not specified.
Remarks
This attribute is optional and is used to reference external methods that you want to use as rule actions. An exception is thrown if the attribute references a non-qualified method. If the external method defines multiple overloads, decorate each overload that you intend to use as a rule action with the [ActionAttribute](/decision-automation/rule-common-attributes-action)
, and assign a unique display name to each using its DisplayName
property.
Remember that external static or instance action methods can accept your source object as a parameter. When a rule author uses such an action in a rule, parameters of the source object type are not displayed — Rule Editor passes them automatically. In the Rule XML, the parameter of the source object type is represented as this
.
The following example illustrates how the rule would appear in Rule Area when a user uses both external actions from the code sample below:
If ID is greater than 10 then Set new ID (0) and Set the Date to UTC
Note that the second method is displayed as parameterless (without parentheses) because it accepts a single parameter of the source type, which is omitted by the editor.
Example
using System;
using CodeEffects.Rule.Common.Attributes;
namespace TestLibrary
{
// This source object contains no actions of its own
// but references 2 external actions declared in the Helper class
[ExternalAction(typeof(Helper), "SetNewDate")]
[ExternalAction(typeof(Helper), "SetNewID")]
public class Thing
{
public int ID {get; set; } = 0;
public DateTime? Date { get; set; }
}
public class Helper
{
[Action("Set new ID", "Sets a new value to the Thing's ID field")]
public void SetNewID(Thing thing, int id)
{
thing.ID = id;
}
[Action("Set the Date to UTC", "Sets a new value to the Thing's Date field")]
public void SetUtcDate(Thing thing)
{
thing.Date = DateTime.UtcNow;
}
}
}