Show Navigation Next Topic  »

Using an Existing .NET Class as a Source Object.

The Source XML topic provides info on how to create source objects manually, from scratch, using a source object's XML schema. But if you already have - or are going to declare - a public .NET class you can set the Rule Editor to use that class as its source object.

Any .NET public class can be used as a source object, provided that it declares at least one public property or one public method that returns a value type (in-rule method). Make sure to read the Code Effects Basics topic for details.

The RuleEditor class declares several properties that you can use to set the type of your source object. The most common is SourceType. The code sample below creates an instance of the RuleEditor with the Patient class as its source type:

CodeEffects.Rule.Web.RuleEditor editor = new RuleEditor("divRuleEditor")
	SourceType = typeof(Patient)

You can also use the full type name of the source object and the name of its declaring assembly:

CodeEffects.Rule.Web.RuleEditor editor = new RuleEditor("divRuleEditor")
	SourceTypeName = "CodeEffects.Rule.Demo.Asp.Core.Models.Patient",
	SourceAssembly = "CodeEffects.Rule.Demo.Asp.Core"

The SourceAssembly property can be the name of the referenced assembly that declares the source object, or the fully qualified name of the assembly that you plan to load programmatically. It can be retrieved as Assembly.GetAssembly(SourceObjectType).FullName. The SourceTypeName property is the full name of the source object's type. It can be retrieved as sourceInstance.GetType().FullName. The RuleEditor class declares more source-related properties that can be used to set the source object.

Our demo projects provide details on how to use .NET classes as source objects in Code Effects.

Comments: 0
Post your questions about Code Effects on Stackoverflow and become a part of our growing community