Closed
Description
Line 109 in 93bc8df
Convert TCSSSelector.AddProperty
to be fluent and to return its Self
instance to enable chained method calls.
Presently, this method is usually called in with statements. That's a code smell that would best be refactoring out. Making this proposed change would make the proposed refactoring easier.
For example, refactoring
with CSSBuilder.AddSelector('a.command-link') do
begin
AddProperty(TCSS.ColorProp(clCommandLink));
AddProperty(TCSS.FontStyleProp(cfsItalic));
AddProperty(TCSS.TextDecorationProp([ctdNone]));
end;
Without the proposed change would result in something like:
var
Sel: TCSSSelector;
begin
Sel := CSSBuilder.AddSelector('a.command-link');
Sel.AddProperty(TCSS.ColorProp(clCommandLink));
Sel.AddProperty(TCSS.FontStyleProp(cfsItalic));
Sel.AddProperty(TCSS.TextDecorationProp([ctdNone]));
end;
While with the fluent version we could write
begin
CSSBuilder.AddSelector('a.command-link')
.AddProperty(TCSS.ColorProp(clCommandLink))
.AddProperty(TCSS.FontStyleProp(cfsItalic))
.AddProperty(TCSS.TextDecorationProp([ctdNone]));
end;
Which doesn't require a local variable and is more readable.