ParentAttribute class

Namespace: CodeEffects.Rule.Attributes
Assembly: CodeEffects.Rule.dll

Sets the display name of the public non-static value type property or field of reference type used in a source object.

Syntax

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

Properties

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

  • ParentName Type: System.String

    Gets or sets the name of the "parent" property of the source object. In the example below, this name is either "ShippingAddress" or "Billing Address".

Example

If a source object contains two or more reference type properties, those properties may be of the same type. For example, consider a Person class that contains two properties of the Address type: ShippingAddress and BillingAddress:

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

namespace TestLibrary
{
	public class Person
	{
		public Address ShippingAddress { get; set; }
		public Address BillingAddrerss { get; set; }
	}

	public class Address
	{
		[Field(ValueInputType = ValueInputType.User, Max = 100)]
		public string Street { get; set; }

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

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

If we leave the code as-is and set the Person class as Code Effects' source object in an ASP.NET page...

<%@ Register assembly="CodeEffects.Rule"
	namespace="CodeEffects.Rule.Asp" tagprefix="rule" %>

<rule:RuleEditor ID="ruleTestControl" runat="server"
	SourceAssembly="TestLibrary"
	SourceType="TestLibrary.Person" />

... we'll see the following list of rule fields when we run the page:

While this may be acceptable for internal solutions, it is likely that you would want to set real display names for the rule fields to make the lives of your business users a bit easier. But simply setting the DisplayName parameter of FieldAttribute of each Address field...

...

	[Field(ValueInputType = ValueInputType.User, Max = 100,
		DisplayName = "Street Address")]
	public string Street { get; set; }

...

... won't work because Code Effects component doesn't know which property to name "Street Address" when it scans the source object while preparing the rule area - ShippingAddress.Street or BillingAddress.Street. If the Street property is modified as shown in the code above, Code Effects will simply use the first property of the Person class that contains the field Street (the ShippingAddress property in this case) and ignore all other "streets" (this is the default behavior):

Use the ParentAttribute to solve this problem. It's easy to understand how it works by looking at the code sample below:

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

namespace TestLibrary
{
	public class Person
	{
		public Address ShippingAddress { get; set; }
		public Address BillingAddress { get; set; }
	}

	public class Address
	{
		[Parent("ShippingAddress", "Shipping street")]
		[Parent("BillingAddress", "Billing street")]
		[Field(ValueInputType = ValueInputType.User, Max = 100)]
		public string Street { get; set; }

		[Parent("ShippingAddress", "Shipping city")]
		[Parent("BillingAddress", "Billing city")]
		[Field(ValueInputType = ValueInputType.User, Max = 50)]
		public string City { get; set; }

		[Parent("ShippingAddress", "Shipping postal code")]
		[Parent("BillingAddress", "Billing postal code")]
		[Field(ValueInputType = ValueInputType.User, Max = 10)]
		public string PostalCode { get; set; }
	}
}

Run the page now and see the difference:

Post your support requests on Stackoverflow.com. You can also post your comments and product feedback using the form at the bottom of this page.
Comments: 0
Name (optional):
Comment (URLs are allowed and must start with http:// or https://; all tags will be encoded):
Remaining character count: