Table of Contents

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

model FieldValueViewModel

The 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

model FieldValueViewModel

The field value model.

Returns

FileViewModel

A FileViewModel built from the path stored in Value when IsFile(FieldValueViewModel) is true; otherwise null.

See Also

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

model FieldValueViewModel

The 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

model FieldValueViewModel

The 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, raw Value, and optional Image path.

See Also

GetValueWithUnits(FieldValueViewModel)

Returns the display value of the field, appending units where applicable.

public static string? GetValueWithUnits(this FieldValueViewModel model)

Parameters

model FieldValueViewModel

The 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.

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

model FieldValueViewModel

The 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)

Returns true if the field holds a file manager path (Type is "Filemanager").

public static bool IsFile(this FieldValueViewModel model)

Parameters

model FieldValueViewModel

The field value model.

Returns

bool

true when Type equals "Filemanager" (case-insensitive); otherwise false.

See Also

Returns true if the field holds a hyperlink value (Type is "Link").

public static bool IsLink(this FieldValueViewModel model)

Parameters

model FieldValueViewModel

The field value model.

Returns

bool

true when Type equals "Link" (case-insensitive); otherwise false.

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

model FieldValueViewModel

The 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

groupFields IList<FieldValueViewModel>

The collection of field values to search.

systemName string

The SystemName to find. The comparison is case-insensitive.

field FieldValueViewModel

When this method returns true, contains the matching FieldValueViewModel; otherwise null.

Returns

bool

true if a field with the given systemName was found; otherwise false.

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

groupFields IList<FieldValueViewModel>

The collection of field values to search.

systemName string

The SystemName to find. The comparison is case-insensitive.

value string

When this method returns true, contains the normalised path:

  • Paths already starting with /Files or Files/ are returned as-is (with a leading / added if missing).
  • All other values are prefixed with /Files/Images/.

Returns

bool

true if the field was found and the resulting path is non-null and non-empty; otherwise false.

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

model FieldValueViewModel

The field value model.

listType FieldListPresentationType?

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

groupFields IList<FieldValueViewModel>

The collection of field values to search.

systemName string

The SystemName to find. The comparison is case-insensitive.

value string

When 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.

Returns

bool

true if the field was found and its string value is non-null and non-empty; otherwise false.

To top