Navigation

Categories
Show Navigation Next Topic  »

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

Syntax

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface,
	AllowMultiple = false, Inherited = false)]
public class SourceAttribute : System.Attribute

When applied to a public class, marks this class as a source object. This attribute is optional. Source objects are a cornerstone element of Code Effects. See the source object topic for details.

Properties

  • DeclaredMembersOnly Type: System.Boolean

    Gets or sets the value indicating whether Rule Editor should only use public members declared by the source object and disregard members of its base class(es). The default value is False. Notice that members of the System.Object class are ignored by Code Effects regardless of the value of this property. This property plays an important role in the technique of preserving attributes in auto-generated classes.

  • MaxTypeNestingLevel Type: System.Int32

    Rule Editor performs a recursive search of all reference type members of the source object and includes all their public value type members not decorated with ExcludeFromEvaluation attribute as rule fields. The recursive search for public value type members is performed up to the level set by this optional property. The default value is 4. Setting this value to high number may slow down the performance of the Rule Editor while it renders itself on a page.

  • PersistTypeNameInRuleXml Type: System.Boolean

    Gets or sets the value indicating whether Rule Editor should store the name of the source object's type in the Rule XML. The default value is True. Set the value of this property to False if you generate source objects dynamically and don't know their types at design time.

  • UseParentFullNamePaths Type: System.Boolean

    Gets or sets the value indicating whether Rule Editor should use dot notation instead of declared names of reference types when it sets DisplayName values of rule fields, in-rule methods and rule actions during recursive search for value type properties. The default value is False.

    Let's consider a plain class Parent with no Code Effects attributes:

    using CodeEffects.Rule.Attributes;
    
    namespace HelloWorld
    {
    	public class Patient
    	{
    		public Middle Test { get; set; }
    	}
    
    	public class Middle
    	{
    		public Address Home { get; set; }
    		public Address Work { get; set; }
    	}
    
    	public class Address
    	{
    		public string Street { get; set; }
    		public string Zip { get; set; }
    	}
    }

    If we run an imaginery web app with Rule Editor and this class as its source object we would see the following field menu:

    full-path-one

    This menu does its job just fine. But it's likely that you would want to have "normal" names for your fields even if they are burried deep inside of your source object. If we decorate this class with SourceAttribute, set the value of its UseParentFullNamePaths property to True, decorate members of the Address class with ParentAttribute, use dot notation to set the exact path of each reference type down to its value types...

    using CodeEffects.Rule.Attributes;
    
    namespace HelloWorld
    {
    	[Source(UseParentFullNamePaths = true)]
    	public class Patient
    	{
    		public Middle Test { get; set; }
    	}
    
    	public class Middle
    	{
    		public Address Home { get; set; }
    		public Address Work { get; set; }
    	}
    
    	public class Address
    	{
    		[Parent("Test.Home", "Home Street")]
    		[Parent("Test.Work", "Work Street")]
    		public string Street { get; set; }
    
    		[Parent("Test.Home", "Home Zip")]
    		[Parent("Test.Work", "Work Zip")]
    		public string Zip { get; set; }
    	}
    }

    ... and then run our project again we get the result we were looking for:

    full-path-two

    As you can see, this property works quite nicely in tandem with ParentAttribute.ParentName if the structure of your source is more complicated than just a single level of reference typed properties or if you don't know the exact structure of your source at design-time. Obviously, if the value of this property if set to True you can use paths with any number of levels as the value of ParentAttribute.ParentName, such as "Test.One.Two.Three.Home".


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

Comments: 0