Navigation

Categories
Show Navigation Next Topic  »

MethodAttribute 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 qualified public method of the source object, marks it 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. This attribute can also be applied to a qualified method of any other public class in order to be usable as an in-rule method. In this case the source object must be decorated with ExternalMethodAttribute which references this method by name and class type.

Syntax

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class MethodAttribute : System.Attribute,
	CodeEffects.Rule.Attributes.IDescribableAttribute

Properties

  • Description Type: System.String

    Gets or sets the description of the in-rule method. Rule authors can see this description when they hover the mouse over the in-rule method 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.

  • DisplayName Type: System.String

    Gets or sets the display name of the in-rule method in Rule Editor. Use this property to "represent" in-rule methods if the method name is not descriptive enough for non-technical rule authors, or if you need to use several overloads of the same method as different in-rule methods. It's not advisable to use this property in multilingual applications; instead, use culture-specific custom Source XML documents. This property is optional. The default value is the declared name of the qualified method.

  • Group Type: System.String

    Gets or sets the name of the menu group of in-rule method in the Rule Editor. This property is optional.

    Example: Your source object could declare dozens if not hundreds of rule fields and in-rule methods. In such case, field menus in Rule Area would include huge number of items and become pretty much unusable. With grouping, you can separate your fields and in-rule methods into groups which Rule Editor uses to present them in two separate menus: first, it displays the list of all available groups and then, when the user selects a group, presents a new menu that displays only items from that group. This feature is automatically enabled if at least one property or in-rule method in your source object has the group name set. The name of the group can be any string. If this feature is enabled, all qualified rule fields and methods that don't have their group set are included in default group called OTHER which is displayed at the bottom of the menu. You can rename that default group using Help XML feature.

    Rule fileds also have this feature. See the MethodAttribute topic for details.

  • Filter Type: System.String

    Gets or sets the name of the menu filter of in-rule method in the Rule Editor. This property is optional.

    Please refer to FieldAttribute topic for details on menu filtering feature.

  • IncludeInCalculations Type: System.Bool

    Used only in in-rule methods that return numeric type, and ignored in all other in-rule methods. Gets or sets the value indicating whether the in-rule method can be included in calculations. This property is optional. The default value is True.

Notes

This attribute is optional. Its purpose is to provide the ability to set the DisplayName and optional Description values for in-rule methods. Rule Editor uses any qualified method of the source object as an in-rule method unless it's decorated with the ExcludeFromEvaluationAttribute. If applied to a non-qualified method, an exception will be thrown. All non-qualified methods that are not decorated with the MethodAttribute will be ignored.

Example

using CodeEffects.Rule.Attributes;

namespace TestLibrary
{
	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; }

		[Method("Full name")]
		public string GetFullName()
		{
			return string.Format("{0}, {1}", this.LastName, this.FirstName);
		}
	}
}

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

Comments: 0