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 what if you already have (or are going to declare) a public .NET class that you'd like Code Effects component to use as a source object? It's simple: just tell Code Effects to use that class.

Any .NET public class can be used as a source object, provided that it meets certain simple rules. Make sure to read the Code Effects Basics topic - it provides definitions of rule elements such as rule fields, actions, or in-rule methods that we refer to in this topic.

In ASP.NET you can simply set the SourceAssembly and SourceType properties of the RuleEditor class to the name of the assembly that declares the source object and the full name of the source object's type:

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

<rule:RuleEditor ID="RuleEditor1" runat="server"
SourceAssembly="AssemblyName"
SourceType="SourceObjectTypeFullName" />

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

In MVC you need to create an instance of the RuleModel class in the controller while the view data is being prepared and then pass it to the view using the model or the ViewBag in order for the RuleEditor to be able to use it:

using CodeEffects.Rule.Models;
...
[HttpGet]
public ActionResult Index()
{
	ViewBag.Rule = RuleModel.Create(typeof(SourceObjectType));
	return View();
}

Now, add RuleEditor to the view, passing it that instance of the RuleModel:

<div>
@{
	Html.CodeEffects().RuleEditor()
		.Id("ruleEditor")
		.SaveAction("Save""ControllerName")
		.DeleteAction("Delete""ControllerName")
		.LoadAction("Load""ControllerName")
		.Mode(RuleType.Execution)
		.Rule(ViewBag.Rule)
		.Render();
}
</div>

The ASP.NET and MVC implementation examples as well as our demo projects provide details on how to use .NET classes as source objects in Code Effects.

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: