Class Builder
- Namespace
- Northwoods.Go
- Assembly
- Northwoods.GoDiagram.WinForms.dll
This static class allows for the creation of GraphObjects via predefined builders, and for the definition of custom builder functions.
public static class Builder
- Inheritance
-
Builder
- Inherited Members
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.
public static void DefineBuilder(string name, Func<object[], GraphObject> func)
Parameters
name
stringa capitalized name; must not be
""
or"None"
func
Func<object[], GraphObject>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>).
public static T Make<T>(string name, params object[] args) where T : GraphObject
Parameters
name
stringa capitalized name of a defined builder
args
object[]a set of arguments to be passed to the builder function
Returns
- T
an GraphObject of type T
Type Parameters
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[])
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.
public static string TakeBuilderArgument(ref object[] args)
Parameters
args
object[]the arguments Array passed to the builder function; this may be modified if an acceptable argument is found and returned
Returns
- string
the first argument
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.
public static object TakeBuilderArgument(ref object[] args, object defval, Predicate<object> pred)
Parameters
args
object[]the arguments Array passed to the builder function; this may be modified if an acceptable argument is found and returned
defval
objectthe default value to return if the argument is optional and not present as the first argument
pred
Predicate<object>a predicate to determine the acceptability of the argument; the default predicate checks whether the argument is a string
Returns
- 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.
public static string TakeBuilderArgument(ref object[] args, string defval)
Parameters
args
object[]the arguments Array passed to the builder function; this may be modified if an acceptable argument is found and returned
defval
stringthe default value if the first argument doesn't exist or isn't a string
Returns
- string
the first argument, if it is a string, or the provided default value