Core Concepts

Why ToGPALObject()

Every With... Setter in a fluent chain returns a configuration interface, not the finished object. ToGPALObject(). Or an equivalent explicit cast. Is the step that turns that configuration into a real, usable GPAL object. Both forms do exactly the same thing; which one to write is a matter of what reads best where it's used.

Two Ways to Finish a Chain

Using ToGPALObject() at the end of a chain and casting the result explicitly to the concrete type are two ways to do the same thing. Each With... Call in the chain returns a configuration interface that only exposes more With... Methods -- it is not the finished object. ToGPALObject() or an explicit cast is what converts that configuration into the real, usable object with all of its members available.

// These two lines are equivalent

Selector sel1 = GPAL.Selector.WithCSS("#username").ToGPALObject();

Selector sel1 = (Selector)GPAL.Selector.WithCSS("#username");

TIP

If you stop at GPAL.Selector.WithCSS("#username") without ToGPALObject() or a cast, the result is still just the configuration interface. Var sel1 = GPAL.Selector.WithCSS("#username"); compiles, but sel1's type only offers more With... Methods. Calling sel1.Remove() on it will not compile. ToGPALObject() or a cast is what gets you the rest of the object's API.

Picking One: Declared Variables vs Inline Arguments

When declaring a variable, ToGPALObject() is usually easier. IntelliSense offers it right at the end of the chain with no need to remember the exact type name. When passing a chain inline as an argument, an explicit cast can read cleaner: the type name up front signals what is being handed over without a trailing ToGPALObject() at the end of a long chain.

// Inline argument - explicit cast reads cleanly as "this is a Button"

GPAL.Form

.WithTitle("Confirm Action")

.WithFormControl((Button)GPAL.Button

.WithText("Proceed")

.WithCallback<EventHandler>(SaveButton_Click)

.ForEvent(ControlEventType.Click))

.ShowDialog();

// Same control, written with ToGPALObject() instead - also correct

GPAL.Form

.WithTitle("Confirm Action")

.WithFormControl(GPAL.Button

.WithText("Proceed")

.WithCallback<EventHandler>(SaveButton_Click)

.ForEvent(ControlEventType.Click)

.ToGPALObject())

.ShowDialog();

TIP

GPAL doesn't enforce either style. Both compile to the same thing. Pick based on what reads best for that line: ToGPALObject() while writing a chain top to bottom, an explicit cast when the chain is just one argument among several.