FieldAttribute 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

If applied to a public non-static value type property or field of the source object (qualified property), references it as a rule field.

Syntax

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field,
	AllowMultiple = false, Inherited = true)]
public class FieldAttribute : System.Attribute,
	CodeEffects.Rule.Attributes.IDescribableAttribute,
	CodeEffects.Rule.Attributes.ISettingsAttribute

Properties

  • AllowCalculations Type: System.Bool

    Used only in rule fields of numeric type. Ignored in fields of other types. Gets or sets the value indicating whether the value element of this field should be allowed to be expressed as a calculation. If set to True, rule authors must select between input and calculation input types before assigning the field's value. This property is optional. The default value is True.

  • CollectionItemName Type: System.String

    Used only in rule fields of collection type, and ignored in fields of other types. Gets or sets the display name of a collection in the rule. Please see the collection support topic for examples and details. This property is optional. The default value is the declared name of the property.

  • CollectionItemType Type: System.Type

    Used only in rule fields of non-generic collection type whose underlying type cannot be determined at run-time (qualified collection). This property is ignored in fields of other types and generic collections. Gets or sets the underlying type of a qualified collection. An example of a qualified collection would be the System.Collections.Specialized.StringCollection or System.Collections.ArrayList. This property is optional. The qualified collection is ignored if the value of this property is not set.

  • DataSourceName Type: System.String

    Used only in rule fields that represent the source object's properties of System.Int type, and ignored in fields of other types. Gets or sets the unique name of the Dynamic Menu Data Source declared by the SourceAttribute on the source object.

  • DateTimeFormat Type: System.String

    Used only in rule fields of date and time types, and ignored in fields of other types. Gets or sets the date or time format of the field's value displayed in the Rule Editor. You can use standard .NET date and time string formatting. This property is not used during rule evaluation. This property is optional. The default value for date fields is "MMM dd, yyyy", and for time fields is "hh:mm tt".

  • Description Type: System.String

    Gets or sets the description of the rule field. Rule authors can see this description when they hover the mouse over the field 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 rule field in the Rule Editor. Use this property to "represent" rule fields on Rule Area if the property name is not descriptive enough for non-technical rule authors. 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 property.

  • Group Type: System.String

    Gets or sets the name of the menu group of the rule field 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 into groups which Rule Editor uses to present fields 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 of the rule fields or in-rule methods in your source object have the group name set. The name of the group can be any string. If this feature is enabled, all rule fields 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 default group using Help XML feature.

    In-rule methods also have this feature. See the MethodAttribute topic for details.

  • Filter Type: System.String

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

    Example: Using this property, you can instruct Rule Editor to allow value comparisons in rule conditions based on the filter value. Let's say that your source object declares four properties of the Stystem.String type:

    using CodeEffects.Rule.Attributes;
    
    namespace TestLibrary
    {
    	public class Thing
    	{
    		[Field(DisplayName = "Work Email")]
    		public string WorkEmail { get; set; }
    
    		[Field(DisplayName = "Home Email")]
    		public string HomeEmail { get; set; }
    
    		[Field(DisplayName = "Work Phone")]
    		public string WorkPhone { get; set; }
    
    		[Field(DisplayName = "Home Phone")]
    		public string HomePhone { get; set; }
    	}
    }

    Having this source the user can create a condition where the phone value is compared to email value. Even though both fields are of the same System.String type, they clearly have nothing in common:

    Let's separate these fields with two filters of "email" and "phone":

    using CodeEffects.Rule.Attributes;
    
    namespace TestLibrary
    {
    public class Thing
    	{
    		[Field(DisplayName = "Work Email", Filter = "email")]
    		public string WorkEmail { get; set; }
    
    		[Field(DisplayName = "Home Email", Filter = "email")]
    		public string HomeEmail { get; set; }
    
    		[Field(DisplayName = "Work Phone", Filter = "phone")]
    		public string WorkPhone { get; set; }
    
    		[Field(DisplayName = "Home Phone", Filter = "phone")]
    		public string HomePhone { get; set; }
    	}
    }

    Now, users will only be able to compare email addresses to other email addresses and phones to other phones:

  • IncludeInCalculations Type: System.Bool

    Used only in rule fields of numeric type, and ignored in fields of other types. Gets or sets the value indicating whether the rule field can be included in value calculations of other fields. For example, it can be distracting to rule authors when a non-financial numeric field ID shows up in a calculation menu among financial fields like Income, Debt, and so on. In such cases, set the IncludeInCalculations to False. This property is optional. The default value is True.

  • Max Type: System.Int64

    Used only with numeric and string value elements, and ignored by other types. For numeric elements, gets or sets the maximum value of the field that rule authors can enter manually. For string elements, gets or sets the maximum length of the string that rule authors can type as the value. Used only by Rule Editor; it's not used in rule evaluations. This property is optional.

  • Min Type: System.Int64

    Used only in rule fields of numeric type, and ignored in fields of other types. Gets or sets the minimum value of the field that rule authors can enter manually. Used only by Rule Editor; it's not used in rule evaluations. This property is optional.

  • Settable Type: System.Bool

    Gets or sets the value indicating whether the value of the rule field can be set in execution type rules. In general, Rule Editor recognizes the readonly fields and properties with private setters; it won't allow the rule authors to set values of those fields and properties. Setting this value to False prevents the rule authors from setting the value of the field or property. The default value is True.

  • StringComparison Type: System.StringComparison

    Used only in rule fields of string types, and ignored by other types. Gets or sets the string comparison option value that will be used to compare string values in rule conditions during evaluation. Can be used to set culture-specific comparison options, including case sensitivity. The default value is System.StringComparison.OrdinalIgnoreCase.

    IMPORTANT! This property is ignored by the rule-based data filtering feature. Use SqlServer's collation to set the string comparison behavior of all selects when using Code Effects with T-SQL LINQ providers such as Entity Framework.

  • ValueInputType Type: CodeEffects.Rule.Common.ValueInputType

    Gets or sets the value indicating whether the field's value can only be typed in manually, or it only accepts fields as a value, or both. For example, consider the rule condition FirstName = John. In this condition, the value is John, which is a string that the rule author typed in. This is a value entered by the "user", i.e. it's of type ValueInputType.User. The same condition can be expressed as FirstName = MiddleName. Since MiddleName is a field, this value was selected by the rule author as a "field" item from the menu, i.e. it's of type ValueInputType.Fields. This property is optional. The default value is ValueInputType.All, which allows both the User and the Fields input types.

Notes

This attribute is optional.

Example

using System;
using CodeEffects.Rule.Attributes;
using CodeEffects.Rule.Common;

namespace TestLibrary
{
	public class Person
	{
		[Field(ValueInputType = ValueInputType.User, Min = 1,
			IncludeInCalculations = false, AllowCalculations = false)]
		public int ID { get; set; }

		[Field(ValueInputType = ValueInputType.User, Max = 30)]
		public string Name { get; set; }

		[Field(ValueInputType = ValueInputType.User, Max = 11,
			DisplayName = "Social security number")]
		public string SSN { get; set; }

		[Field(DateTimeFormat = "MM/dd/yyyy", DisplayName = "Date of birth")]
		public DateTime DOB { get; set; }

		[Field(DateTimeFormat = "hh:mm:ss tt", DisplayName = "Time of birth")]
		public TimeSpan? TOB { get; set; }

		[Field(Min = 0, Max = 1000000, DisplayName = "Total debt")]
		public decimal? Debt { get; set; }

		[Field(Min = 0, Max = 1000000, DisplayName = "Monthly income")]
		public decimal Income { get; set; }

		[Field(ValueInputType = ValueInputType.User)]
		public bool Married { get; set; }

		[Field(ValueInputType = ValueInputType.User)]
		public Gender Gender { get; set; }
	}

	public enum Gender
	{
		Male,
		Female,
		[ExcludeFromEvaluation]
		Unknown
	}
}
Comments: 0
Post your questions about Code Effects on Stackoverflow.com
and become a part of our growing community
Name (optional):
Comment (URLs are allowed and must start with http:// or https://; all tags will be encoded):
Remaining character count: