Class Builder

GoDiagram®
v10.0.11
by Northwoods Software®

This static class allows for the creation of GraphObjects via predefined builders, and for the definition of custom builder functions.

Inheritance
Builder
Namespace: Northwoods.Go
Assembly: Northwoods.GoDiagram.Avalonia.dll
Syntax
public static class Builder
Remarks

Predefined builder names include: "Button", "TreeExpanderButton", "SubGraphExpanderButton", "PanelExpanderButton", and "ContextMenuButton". The implementation of these builders is provided by Buttons.cs in the Extensions directory.

Methods

DefineBuilder(string, Func<object[], GraphObject>)

This static function defines a named function that Make<T>(string, params object[]) can use to build elements. Once this is called one can use the name as the first argument for Make<T>(string, params object[]). Names are case sensitive.

Declaration
public static void DefineBuilder(string name, Func<object[], GraphObject> func)
Parameters
Type Name Description
string name

a capitalized name; must not be "" or "None"

Func<object[], GraphObject> func

takes an array of arguments and returns a new GraphObject

Remarks

The second argument must be a function that returns a newly created element, typically a GraphObject. It is commonplace for that element to be a Panel holding a newly created visual tree of GraphObjects. The function receives as its only argument an Array that is holds all of the arguments that are being passed to Make<T>(string, params object[]), which it may modify in order to change the arguments that Make receives.

Predefined builder names include: "Button", "TreeExpanderButton", "SubGraphExpanderButton", "PanelExpanderButton", and "ContextMenuButton". The implementation of these builders is provided by Buttons.cs in the Extensions directory.

Make<T>(string, params object[])

Build a GraphObject from a predefined builder function or from one defined by DefineBuilder(string, Func<object[], GraphObject>).

Declaration
public static T Make<T>(string name, params object[] args) where T : GraphObject
Parameters
Type Name Description
string name

a capitalized name of a defined builder

object[] args

a set of arguments to be passed to the builder function

Returns
Type Description
T

an GraphObject of type T

Type Parameters
Name Description
T

the desired return type of the make function

Remarks
Builder.Make<Panel>("ContextMenuButton")
  .Add(new TextBlock(text))
  .Set(new { Click = action })
  .Bind(visiblePred != null ? new Binding("Visible", "", visiblePred).OfElement() : null);

TakeBuilderArgument(ref object[], object, Predicate<object>)

This static method returns the first argument from the arguments passed to Make<T>(string, params object[]). By default this requires the first argument to be a string, but you can provide a predicate to determine whether the argument is suitable.

Declaration
public static object TakeBuilderArgument(ref object[] args, object defval, Predicate<object> pred)
Parameters
Type Name Description
object[] args

the arguments Array passed to the builder function; this may be modified if an acceptable argument is found and returned

object defval

the default value to return if the argument is optional and not present as the first argument

Predicate<object> pred

a predicate to determine the acceptability of the argument; the default predicate checks whether the argument is a string

Returns
Type Description
object

the first argument or the provided default value

TakeBuilderArgument(ref object[], string)

This static method returns the first argument from the arguments passed to Make<T>(string, params object[]). The first argument should be a string. If it isn't, the default value will be returned.

Declaration
public static string TakeBuilderArgument(ref object[] args, string defval)
Parameters
Type Name Description
object[] args

the arguments Array passed to the builder function; this may be modified if an acceptable argument is found and returned

string defval

the default value if the first argument doesn't exist or isn't a string

Returns
Type Description
string

the first argument, if it is a string, or the provided default value

TakeBuilderArgument(ref object[])

This static method returns the first argument from the arguments passed to Make<T>(string, params object[]). This requires the first argument to be a string.

Declaration
public static string TakeBuilderArgument(ref object[] args)
Parameters
Type Name Description
object[] args

the arguments Array passed to the builder function; this may be modified if an acceptable argument is found and returned

Returns
Type Description
string

the first argument