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 source model as in-rule methods or rule actions. Use Reflection model 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

Constructors

  • ExternalMethodAttribute()

    Initializes a new instance of the attribute with the default values of all properties.

  • ExternalMethodAttribute(Type type, string methodName)

    Initializes a new instance of the attribute that references the external in-rule method by the type that declares it.

    Parameters

    • type (System.Type) - The type that declares the external in-rule method.
    • methodName (System.String) - The declared name of the external in-rule method.
  • ExternalMethodAttribute(Type type, string methodName, bool gettable)

    Initializes a new instance of the attribute that references the in-rule method by the type that declares it, and sets whether the method is offered as the subject of a condition.

    Parameters

    • type (System.Type) - The type that declares the in-rule method.
    • methodName (System.String) - The declared name of the in-rule method.
    • gettable (System.Boolean) - false keeps the method out of the menu of condition subjects only; it can still be picked as a value, in calculations and in parameters. Same as MethodAttribute.Gettable.
  • ExternalMethodAttribute(string declaringTypeOrAliasName, string methodName)

    Initializes a new instance of the attribute that references the external in-rule method by the assembly-qualified name or the alias name of the type that declares it.

    Parameters

    • declaringTypeOrAliasName (System.String) - The assembly-qualified name or alias name of the type that declares the external in-rule method.
    • methodName (System.String) - The declared name of the external in-rule method.
  • ExternalMethodAttribute(string declaringTypeOrAliasName, string methodName, bool gettable)

    Initializes a new instance of the attribute that references the in-rule method by the name of the type that declares it, and sets whether the method is offered as the subject of a condition.

    Parameters

    • declaringTypeOrAliasName (System.String) - The assembly-qualified name or alias name of the type that declares the in-rule method.
    • methodName (System.String) - The declared name of the in-rule method.
    • gettable (System.Boolean) - false keeps the method out of the menu of condition subjects only. Same as MethodAttribute.Gettable.
  • ExternalMethodAttribute(string assemblyName, string declaringTypeOrAliasName, string methodName)

    Deprecated. This constructor is obsolete and will be removed in a future major version. Use ExternalMethodAttribute(string declaringTypeOrAliasName, string methodName) instead, passing the AssemblyQualifiedName of the type that declares the external in-rule method.

    Initializes a new instance of the attribute.

    Parameters

    • assemblyName (System.String) - The name of the assembly that declares the type.
    • declaringTypeOrAliasName (System.String) - The name of the type.
    • methodName (System.String) - The declared name of the external in-rule method.
  • ExternalMethodAttribute(string assemblyName, string declaringTypeOrAliasName, string methodName, bool gettable)

    Deprecated. This constructor is obsolete and will be removed in a future major version. Use ExternalMethodAttribute(string declaringTypeOrAliasName, string methodName, bool gettable) instead, passing the AssemblyQualifiedName of the type that declares the external method.

    Initializes a new instance of the attribute.

    Parameters

    • assemblyName (System.String) - The name of the assembly that declares the type.
    • declaringTypeOrAliasName (System.String) - The name of the type.
    • methodName (System.String) - The declared name of the in-rule method.
    • gettable (System.Boolean) - Whether the method is offered as the subject of a condition.

Properties

  • Assembly

    Type: System.String

    Deprecated. This property is obsolete and will be removed in a future major version. Use TypeOrAliasName and set it to the AssemblyQualifiedName of the type that declares the external in-rule method.

    Always returns null.

  • Method

    Type: System.String

    Gets the name of the method declared outside the source object that Rule Editor uses as an in-rule method.

  • 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.

  • TestMethodName

    Type: System.String

    Gets or sets the name of the method that the Code Effects Rule Repository calls instead of the external one when a rule is tested. The test method takes the object the rule is evaluated against first, then the parameters that the external method takes from the rule; a parameter of the source object type of the external method is not repeated. Overrides a TestMethodName declared by the external method's own MethodAttribute. Ignored outside a Rule Repository test. This property is optional.

  • TestMethodType

    Type: System.Type

    Gets or sets the class that declares the test method named by TestMethodName. When this property is not set, the class that declares the external method is used. A static test method is called on the class; an instance one is called on the evaluated object when this is the object's class (then it takes only the external method's parameters from the rule), otherwise on a new instance, which requires a public parameterless constructor. Ignored outside a Rule Repository test. This property is optional.

  • Type

    Type: System.Type

    Gets the type of the class that declares the external in-rule method. This property is null if the attribute was created with a type name; then TypeOrAliasName is set instead.

  • TypeName

    Type: System.String

    Deprecated. This property is obsolete and will be removed in future versions. Use TypeOrAliasName instead.

    Returns the value of TypeOrAliasName.

  • TypeOrAliasName

    Type: System.String

    Gets the assembly-qualified name or the alias name of the type that declares the external in-rule method. You can obtain the assembly-qualified name by executing typeof(ClassName).AssemblyQualifiedName. This property is null if the attribute was created with a System.Type; then Type is set instead.

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, 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;
		}
	}
}

Ask on Stack Overflow - Yes, it's still active
Ask in GitHub Discussions

p102

l097 --

l102

p101

×