Class FacetOptionViewModelExtensions
- Namespace
- Dynamicweb.Ecommerce.ProductCatalog
- Assembly
- Dynamicweb.Ecommerce.dll
Provides extension methods for the FacetOptionViewModel class.
public static class FacetOptionViewModelExtensions
- Inheritance
-
FacetOptionViewModelExtensions
- Inherited Members
Methods
TryGetColor(FacetOptionViewModel, out ColorViewModel?)
Tries to get the color from the facet option if it is a hex value or if it is a variant option with a color set on it.
public static bool TryGetColor(this FacetOptionViewModel facetOption, out ColorViewModel? color)
Parameters
facetOptionFacetOptionViewModelThe facet option to get the color from.
colorColorViewModelThe color view model if the color is successfully retrieved, otherwise null.
Returns
- bool
True if the color is successfully retrieved, otherwise false.
Remarks
This method tries to get the color from the facet option by following these steps:
- If the facet option is null, it sets the color to null and returns false.
- If the facet option value starts with '#' and has a length of 7 or 4, it creates a new ColorViewModel with the facet option value as the Hex property and returns true.
- It tries to get the variant option using the facet option value. If the variant option is not null and has a non-empty color, it creates a new ColorViewModel with the variant color and returns true.
- If none of the above conditions are met, it sets the color to null and returns false.