Atlas
Atlas copied to clipboard
IFieldRenderString methods are not as usable as they could be
In the IFieldRenderingString interface we have three methods, WithAttribute, DisableWebEdit, and DefaultValueIfEmpty.
These methods return IFieldRenderingString (the this
), and were intended to be builder methods to let the user build up the desired behaviour, e.g.
MyField.DisableWebEdit().DefaultValueIfEmpty("I'm empty!");
When you use these methods you are coerced to IFieldRenderingString
which can be annoying if your field was more derived, such as LinkFieldRenderingString
.
These methods would be better as extension methods, that use a generic parameter constrained to IFieldRenderingString. i.e.
public static T DisableWebEdit<T>(this T field) where T : IFieldRenderingString
This would allow the builder pattern on any of the field rendering types that derive from IFieldRenderingString
, without the coercion, e.g. after using DisableWebEdit()
the field is still a LinkFieldRenderingString and not a boring old IFieldRenderingString.
Changing the interface is a breaking change. Adding equivalent extension methods would help, but any code that references Atlas would have to be recompiled.