Class FieldValueViewModelExtensionMethods
- Namespace
- Dynamicweb.Ecommerce.ProductCatalog
- Assembly
- Dynamicweb.Ecommerce.dll
Extension methods for FieldValueViewModel and collections of it.
public static class FieldValueViewModelExtensionMethods
- Inheritance
-
FieldValueViewModelExtensionMethods
- Inherited Members
Remarks
Two groups of methods are provided:
-
Collection methods (
TryGetField,TryGetString,TryGetImagePath) — operate on IList<T> of FieldValueViewModel and look up a field by SystemName before returning its value. -
Instance methods (
Is*,Get*,TryGetListType,GetValueWithUnits) — operate on a single FieldValueViewModel and interpret or convert its Value based on Type.
Methods
GetColor(FieldValueViewModel)
Returns a ColorViewModel for a color field, or null if the field is not a color.
public static ColorViewModel? GetColor(this FieldValueViewModel model)
Parameters
modelFieldValueViewModelThe field value model.
Returns
- ColorViewModel
A ColorViewModel built from the hex string stored in Value when IsColor(FieldValueViewModel) is true; otherwise null.
- See Also
GetFile(FieldValueViewModel)
Returns a FileViewModel for a file manager field, or null if the field is not a file.
public static FileViewModel? GetFile(this FieldValueViewModel model)
Parameters
modelFieldValueViewModelThe field value model.
Returns
- FileViewModel
A FileViewModel built from the path stored in Value when IsFile(FieldValueViewModel) is true; otherwise null.
- See Also
GetLink(FieldValueViewModel)
Returns a resolved LinkViewModel for a link field, or null if the field is not a link.
public static LinkViewModel? GetLink(this FieldValueViewModel model)
Parameters
modelFieldValueViewModelThe field value model.
Returns
- LinkViewModel
A LinkViewModel built from the raw string stored in Value when IsLink(FieldValueViewModel) is true; otherwise null.
- See Also
GetList(FieldValueViewModel)
Returns the selected options for a list field, or an empty list if the field is not a list.
public static List<FieldOptionValueViewModel> GetList(this FieldValueViewModel model)
Parameters
modelFieldValueViewModelThe field value model.
Returns
- List<FieldOptionValueViewModel>
The List<T> of FieldOptionValueViewModel stored in Value when IsList(FieldValueViewModel) is true; otherwise an empty list. Each element carries the option
Name, rawValue, and optionalImagepath.
- See Also
GetValueWithUnits(FieldValueViewModel)
Returns the display value of the field, appending units where applicable.
public static string? GetValueWithUnits(this FieldValueViewModel model)
Parameters
modelFieldValueViewModelThe field value model.
Returns
- string
- For a single-option list field: the option name (which may include a unit suffix, e.g.
"10 kg"). - For all other field types: the result of calling ToString() on Value.
- null if Value is null.
- For a single-option list field: the option name (which may include a unit suffix, e.g.
Remarks
Unlike ToString(), this method does not flatten multi-option lists to a comma-separated string — it only unwraps the first option. Use GetList(FieldValueViewModel) when you need all selected options for a multi-select field.
IsColor(FieldValueViewModel)
Returns true if the field holds a color value (the resolved value starts with #).
public static bool IsColor(this FieldValueViewModel model)
Parameters
modelFieldValueViewModelThe field value model.
Returns
- bool
true when the effective field value is a non-empty string whose first non-whitespace character is
#(a hex color code); otherwise false.
Remarks
Detection is based on the value content rather than Type because color
fields do not have a dedicated type alias — they are stored as plain text fields whose value happens to be
a hex color. The check is applied after passing through GetCorrectFieldValue, which unwraps
single-item option lists before comparing.
- See Also
IsFile(FieldValueViewModel)
public static bool IsFile(this FieldValueViewModel model)
Parameters
modelFieldValueViewModelThe field value model.
Returns
- See Also
IsLink(FieldValueViewModel)
public static bool IsLink(this FieldValueViewModel model)
Parameters
modelFieldValueViewModelThe field value model.
Returns
- See Also
IsList(FieldValueViewModel)
Returns true if the field is a list field with at least one selected option.
public static bool IsList(this FieldValueViewModel model)
Parameters
modelFieldValueViewModelThe field value model.
Returns
- bool
true when Type is
"List"and Value is a non-empty List<T> of FieldOptionValueViewModel; otherwise false.
- See Also
TryGetField(IList<FieldValueViewModel>, string, out FieldValueViewModel?)
Looks up a field by system name in a collection and assigns it to the out parameter.
public static bool TryGetField(this IList<FieldValueViewModel> groupFields, string systemName, out FieldValueViewModel? field)
Parameters
groupFieldsIList<FieldValueViewModel>The collection of field values to search.
systemNamestringThe SystemName to find. The comparison is case-insensitive.
fieldFieldValueViewModelWhen this method returns true, contains the matching FieldValueViewModel; otherwise null.
Returns
TryGetImagePath(IList<FieldValueViewModel>, string, out string?)
Looks up a field by system name and assigns a normalised, root-relative image path to the out parameter.
public static bool TryGetImagePath(this IList<FieldValueViewModel> groupFields, string systemName, out string? value)
Parameters
groupFieldsIList<FieldValueViewModel>The collection of field values to search.
systemNamestringThe SystemName to find. The comparison is case-insensitive.
valuestringWhen this method returns true, contains the normalised path:
- Paths already starting with
/FilesorFiles/are returned as-is (with a leading/added if missing). - All other values are prefixed with
/Files/Images/.
- Paths already starting with
Returns
TryGetListType(FieldValueViewModel, out FieldListPresentationType?)
Returns true if the field is a list field and assigns its FieldListPresentationType to the out parameter.
public static bool TryGetListType(this FieldValueViewModel model, out FieldListPresentationType? listType)
Parameters
modelFieldValueViewModelThe field value model.
listTypeFieldListPresentationType?When this method returns true, contains the FieldListPresentationType corresponding to ListType; otherwise null.
Returns
- bool
true if ListType maps to a defined FieldListPresentationType member (i.e. the field is a list field); false when ListType is
0(not a list field) or an unrecognised value.
- See Also
TryGetString(IList<FieldValueViewModel>, string, out string?)
Looks up a field by system name and assigns its string representation to the out parameter.
public static bool TryGetString(this IList<FieldValueViewModel> groupFields, string systemName, out string? value)
Parameters
groupFieldsIList<FieldValueViewModel>The collection of field values to search.
systemNamestringThe SystemName to find. The comparison is case-insensitive.
valuestringWhen this method returns true, contains the result of ToString() for the matched field; otherwise null. For list fields this is a comma-separated string of selected option names.