Navigation

Categories
Show Navigation Next Topic  »

ExternalMethodAttribute class

Namespace: CodeEffects.Rule.Attributes
Assemblies: CodeEffects.Rule.Editor.Asp.dll, CodeEffects.Rule.Editor.Mvc.dll, CodeEffects.Rule.Editor.Core.dll, CodeEffects.Rule.Editor.Net.dll

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.

If applied to a source object, references an external qualified public method as an in-rule method. To qualify, the method must return a value type and be parameterless or have only parameters of source object type or any value type supported by Code Effects.

Syntax

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface,
	AllowMultiple = true, Inherited = true)]
public class ExternalMethodAttribute : System.Attribute,
	CodeEffects.Rule.Attributes.IExternalAttribute,
	CodeEffects.Rule.Attributes.ISortable

Properties

  • Assembly Type: System.String

    Gets or sets the full name of the assembly that declares the method class, which can be obtained by executing Assembly.GetAssembly( className ).FullName. If the Type property is not set, this property is required.

  • Method Type: System.String

    Gets or sets the name of the in-rule method declared outside of the source object. This is a required property.

  • SortOrder Type: System.Int16

    Gets or sets the sort order in which the in-rule method is placed in fields menu on Rule Area. This property is optional. Default value is 0.

  • Type Type: System.Type

    Gets or sets the type of the class that declares the external in-rule method. If the Assembly and TypeName properties are not set, this property is required.

  • TypeName Type: System.String

    Gets or sets the full name of the type of the class that declares the external in-rule method, which can be obtained by executing typeof( className ).FullName. If the Type property is not set, this property is required.

Notes

This attribute is optional. Its purpose is to provide references to in-rule methods declared outside of the source object. An exception will be thrown if this attribute points to a non-qualified method. If the external method declares multiple overloads, decorate each overload that you would like to use as an in-rule method with the MethodAttribute and set its DisplayName property to a unique display name.

Example

using System;
using CodeEffects.Rule.Attributes;

namespace TestLibrary
{
	// The source object references an 
	// external method declared in the Helper class
	[ExternalMethod(typeof(Helper), "GetFullName")]
	public class Person
	{
		[Field(DisplayName = "First name", Max = 30)]
		public string FirstName { get; set; }

		[Field(DisplayName = "Last name", Max = 30)]
		public string LastName { get; set; }
	}

	public class Helper
	{
		[Method("Full name", "Joins first and last names")]
		public string GetFullName(Person person)
		{
			return string.Format(
				"{0}, {1}", person.LastName, person.FirstName);
		}
	}
}

Post your questions on Stackoverflow and become a part of our growing community

Comments: 0