ExternalMethodAttribute 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 an in-rule method. To qualify, the method must be public, static or instance, return a value type and must either be parameterless or declare only parameters of the source object type or of any value type supported by Code Effects.
Syntax
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
public class ExternalMethodAttribute : 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 in-rule 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 an in-rule method. 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 an in-rule method. 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 in-rule rule method appears in the field 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 in-rule 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 in-rule 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 in-rule methods. 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 an in-rule method with the [MethodAttribute](/decision-automation/rule-common-attributes-method), and assign a unique display name to each using its DisplayName property.
Remember that external static or instance in-rule methods can accept your source object as a parameter. When a rule author uses such a method 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.
Example
using System;
using CodeEffects.Rule.Common.Attributes;
namespace TestLibrary
{
[ExternalMethod(typeof(Helper), nameof(Helper.GetUtc))]
public class Test
{
// Class implementation
}
public class Helper
{
[Method("Get UTC Date", "Gets a new UTC value")]
public static DateTime GetUtc()
{
return DateTime.UtcNow;
}
}
}