Source Class

Assembly: CodeEffects.Rule.Editor.dll
Namespace: CodeEffects.Rule.Editor.Models

Summary

Holds the elements of a source object as Adaptive Source metadata: its fields, in-rule methods, actions, enumerations, and data sources. An ISourceProvider returns the whole source from GetSource(). The static methods of this class build these elements from a .NET type, so a provider whose model is a class does not have to describe every member by hand.

Syntax

public class Source

Properties

  • Actions

    Type: System.Collections.Generic.ICollection<CodeEffects.Rule.Editor.Client.Function>

    Gets or sets the actions of the source: the methods that return nothing and that execution type rules call. The default value is an empty collection.

  • AiAliases

    Type: System.Collections.Generic.IList<System.String>

    Gets or sets the other names an AI agent may know the source object by. It is read from ISourceProvider.GetSource() only: the Rule Repository writes the aliases into the main source element of the stored document, and the Rule Editor never uses them. The default value is null.

  • AiDescription

    Type: System.String

    Gets or sets what an AI agent should know about the source object. It is read from ISourceProvider.GetSource() only, as AiAliases is. The default value is null.

  • CacheID

    Type: System.String

    Gets or sets the ID the editor caches this source under on the client. When the editor builds a source from an ISourceElements, it takes the ID from there.

  • CorrelationField

    Type: System.String

    Gets or sets the field of the main object whose value the application passes as the correlation ID of each evaluation. Name the field by its Value (Loan.LoanNumber) or by its name alone (LoanNumber). It must be a string or numeric field of the main object, not one reached through a reference property. It is read from ISourceProvider.GetSource() only, as AiAliases is, and the Rule Editor never uses it. The default value is null.

  • DataSources

    Type: System.Collections.Generic.ICollection<CodeEffects.Rule.Editor.Client.DataSource>

    Gets or sets the Dynamic Menu Data Sources the members of the source use. The default value is an empty collection.

  • Enums

    Type: System.Collections.Generic.ICollection<CodeEffects.Rule.Editor.Client.Enum>

    Gets or sets the enumerations the members of the source use, each with its members. The default value is an empty collection.

  • Fields

    Type: System.Collections.Generic.ICollection<CodeEffects.Rule.Editor.Client.Field>

    Gets or sets the fields of the source. The default value is an empty collection.

  • Functions

    Type: System.Collections.Generic.ICollection<CodeEffects.Rule.Editor.Client.Function>

    Gets or sets the in-rule methods of the source: the methods that return a value and that rules call from their conditions. The default value is an empty collection.

Methods

All methods of this class are static.

  • AllowsFractions

    Returns: System.Boolean

    Returns true if the type is System.Single, System.Double, or System.Decimal, or the nullable form of one of them, and false for every other type.

    Parameters

    • type (System.Type) - The type to check.
  • GetDataSources

    Returns: System.Collections.Generic.ICollection<CodeEffects.Rule.Editor.Client.DataSource>

    Returns the Dynamic Menu Data Sources that the DataAttribute declarations on the type, on its base types, and on the interfaces it implements describe. Each result carries the name, type, and method of its attribute, so the Rule Repository can call the method for the items.

    Parameters

    • sourceObject (System.Type) - The type of the source object.
  • GetEnum

    Returns: CodeEffects.Rule.Editor.Client.Enum

    Returns the metadata of an enumeration with its members. Each member's ID is its numeric value as a string. Its Name is the DisplayName of its EnumItemAttribute if it has one, otherwise the name of the member. A Nullable<T> of an enumeration is unwrapped. Throws a SourceException if the type is null or is not an enumeration.

    Parameters

    • enumType (System.Type) - The enumeration type.
    • enumName (System.String) - The name to give the result. It is what fields and parameters that use the enumeration refer to.
  • GetFields

    Returns: System.Collections.Generic.ICollection<CodeEffects.Rule.Editor.Client.Field>

    Returns the fields of a .NET type, built from its public instance properties and their FieldAttribute settings. A property marked with ExcludeFromEvaluationAttribute, a property of type System.Guid, and a property of a type the editor does not support are left out. The Value of each field is the simple name of the type, a dot, and the property name, with the path of the parent properties in between for a nested property (Loan.Amount).

    The SourceAttribute of the type decides which properties are included: DeclaredMembersOnly (the default is true, which excludes inherited members) and MaxTypeNestingLevel (without the attribute, only the direct properties of the type are included). When you pass names, only the properties on those paths are returned, at any depth, and the nesting level is ignored for them. Throws a SourceException if sourceObject is null.

    Parameters

    • sourceObject (System.Type) - The type of the source object.
    • nameKind (CodeEffects.Rule.Editor.Models.TypeNameKind) - The form of type names the fields use where they name a type, such as the type of a collection element or of an enumeration.
    • names (System.Collections.Generic.ICollection<System.String>) - Optional. The paths of the properties to return, such as Address.City. The default value is null, which returns all fields.
  • GetMethods

    Returns: System.Collections.Generic.ICollection<CodeEffects.Rule.Editor.Client.Function>

    Returns the in-rule methods or the actions of a .NET type, built from its public methods and their MethodAttribute or ActionAttribute settings, and from the external methods or actions that ExternalMethodAttribute or ExternalActionAttribute declarations on the type name. A method marked with ExcludeFromEvaluationAttribute is left out. An in-rule method must return a value of a supported scalar type, and an action must return void. Where a name has overloads, the result holds one of them, preferring the one that carries the attribute. Throws a SourceException if sourceObject is null, or if the type of an external method cannot be loaded.

    Parameters

    • sourceObject (System.Type) - The type of the source object.
    • inRuleMethods (System.Boolean) - true to return in-rule methods, false to return actions.
    • nameKind (CodeEffects.Rule.Editor.Models.TypeNameKind) - The form of type names the results use where they name a type.
    • typeResolver (CodeEffects.Rule.Common.Models.GetTypeDelegate) - Optional. Loads the type of an external method that is given by an alias. The default value is null.
    • names (System.Collections.Generic.ICollection<System.String>) - Optional. The names of the methods to return. The default value is null, which returns all methods.
  • GetName

    Returns: System.String

    Returns the name of a type as the editor writes it into a source: the TypeOrAliasName of the type's SourceAttribute if it has one, otherwise the assembly-qualified name, the full name, or the simple name of the type, as naming says.

    Parameters

  • GetSourceTypes

    Returns: System.Collections.Generic.ICollection<System.Type>

    Returns the type itself followed by every class or interface type it reaches through its properties of generic collection types, each once, in the order found. A source object that has reference-typed collections is described by one set of fields and methods per returned type. Throws a SourceException if the type is null.

    Parameters

    • sourceObject (System.Type) - The type of the source object.

Example

The following GetSource method of an ISourceProvider builds the whole source from a class:

public Source GetSource()
{
	var source = new Source();

	foreach(var type in Source.GetSourceTypes(typeof(Loan)))
	{
		foreach(var field in Source.GetFields(type, TypeNameKind.FullName)) source.Fields.Add(field);
		foreach(var method in Source.GetMethods(type, true, TypeNameKind.FullName)) source.Functions.Add(method);
		foreach(var action in Source.GetMethods(type, false, TypeNameKind.FullName)) source.Actions.Add(action);
	}

	return source;
}

Ask on Stack Overflow - Yes, it's still active
Ask in GitHub Discussions

p102

l097 --

l102

p101

×