Using an Existing .NET Class as a Source Object

The Source XML topic explains how to create source objects manually from scratch using a source object’s XML schema. However, if you already have — or plan to declare — a public .NET class, you can configure the Rule Editor to use that class as its source object.

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

The CodeEffects.Rule.Editor.Control class declares several properties you can use to specify the type of your source object. The most common is SourceType. The code sample below creates an instance of the Control with the Patient class as its source type:

using CodeEffects.Rule Editor;

var editor = new Control("divRuleEditorId")
{
    SourceType = typeof(Patient)
};

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

using CodeEffects.Rule Editor;

var editor = new Control("divRuleEditorId")
{
    SourceTypeName = "CodeEffects.Rule.Demo.Models.Patient",
    SourceAssembly = "CodeEffects.Rule.Demo"
};

The SourceAssembly property of the Control can be either 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 Control class declares additional source-related properties that can also be used to configure the source object.

Our demo projects provide detailed examples of how to use .NET classes as source objects in Code Effects.

p101

l097 --

l102

p101

×