Show / Hide Table of Contents

Class ImageExtensions

Extension methods for adaptive image properties.

Inheritance
object
ImageExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: AdaptiveImages.Core
Assembly: AdaptiveImages.dll
Syntax
public static class ImageExtensions

Methods

AssignTo(SingleImage?, AdaptiveImage)

Copies all properties from one SingleImage instance to each form factor of an AdaptiveImage instance.

Declaration
public static void AssignTo(this SingleImage? image, AdaptiveImage property)
Parameters
Type Name Description
SingleImage image
AdaptiveImage property
Remarks

Convenience method since Optimizely does not support setting a block property value to a block instance directly

AssignTo(SingleImage?, SingleImage)

Copies all properties from one SingleImage instance to another.

Declaration
public static void AssignTo(this SingleImage? image, SingleImage property)
Parameters
Type Name Description
SingleImage image
SingleImage property
Remarks

Convenience method since Optimizely does not support setting a block property value to a block instance directly

GetCropSettings(SingleImage?)

Gets crop settings for an image and calculates the resulting cropped image size based on the image's original file size.

Declaration
public static CropSettings GetCropSettings(this SingleImage? image)
Parameters
Type Name Description
SingleImage image
Returns
Type Description
CropSettings

GetCropSettings<TImage, TProperty>(TImage, Expression<Func<TImage, TProperty>>)

Calculates the dimensions of a cropped image based on its crop settings, if any.

Declaration
public static CropSettings GetCropSettings<TImage, TProperty>(this TImage image, Expression<Func<TImage, TProperty>> expression) where TImage : AdaptiveImage? where TProperty : SingleImage?
Parameters
Type Name Description
TImage image
Expression<Func<TImage, TProperty>> expression
Returns
Type Description
CropSettings
Type Parameters
Name Description
TImage
TProperty

GetCultureSpecificImageAttribute<TContent, TProperty>(TContent, Expression<Func<TContent, TProperty>>)

Used to get the CultureSpecificImageAttribute attribute of a specific AdaptiveImage or SingleImage property.

Declaration
public static CultureSpecificImageAttribute? GetCultureSpecificImageAttribute<TContent, TProperty>(this TContent content, Expression<Func<TContent, TProperty>> expression)
Parameters
Type Name Description
TContent content
Expression<Func<TContent, TProperty>> expression
Returns
Type Description
CultureSpecificImageAttribute
Type Parameters
Name Description
TContent
TProperty

GetFormFactor(string)

Used to resolve a form factor based on its name.

Declaration
public static FormFactor GetFormFactor(string name)
Parameters
Type Name Description
string name
Returns
Type Description
FormFactor

GetFormFactor<TImage, TProperty>(TImage, Expression<Func<TImage, TProperty>>)

Identifies the correct form factor for an image details property.

Declaration
public static FormFactor GetFormFactor<TImage, TProperty>(this TImage image, Expression<Func<TImage, TProperty>> expression) where TImage : AdaptiveImage? where TProperty : SingleImage?
Parameters
Type Name Description
TImage image
Expression<Func<TImage, TProperty>> expression
Returns
Type Description
FormFactor
Type Parameters
Name Description
TImage
TProperty

GetImageByFormFactor<T>(T, FormFactor)

Gets image details for a specific form factor.

Declaration
public static SingleImage GetImageByFormFactor<T>(this T adaptiveImage, FormFactor formFactor) where T : AdaptiveImage
Parameters
Type Name Description
T adaptiveImage
FormFactor formFactor
Returns
Type Description
SingleImage
Type Parameters
Name Description
T

GetImageByFormFactor<TContent, TProperty>(TContent, Expression<Func<TContent, TProperty>>, FormFactor)

Gets image details for a specific form factor.

Declaration
public static SingleImage GetImageByFormFactor<TContent, TProperty>(this TContent content, Expression<Func<TContent, TProperty>> expression, FormFactor formFactor) where TContent : AdaptiveImage? where TProperty : AdaptiveImage?
Parameters
Type Name Description
TContent content
Expression<Func<TContent, TProperty>> expression
FormFactor formFactor
Returns
Type Description
SingleImage
Type Parameters
Name Description
TContent
TProperty

GetImageConstraints(MemberInfo)

Gets image constraints for a specific property .

Declaration
public static ImageConstraints GetImageConstraints(this MemberInfo memberInfo)
Parameters
Type Name Description
MemberInfo memberInfo
Returns
Type Description
ImageConstraints

GetImageConstraints<TParent>(TParent, string)

Gets image constraints for a specific property.

Declaration
public static ImageConstraints GetImageConstraints<TParent>(this TParent parent, string propertyName) where TParent : class
Parameters
Type Name Description
TParent parent
string propertyName
Returns
Type Description
ImageConstraints
Type Parameters
Name Description
TParent
Exceptions
Type Condition
NotSupportedException

GetImageConstraints<TParent, TProperty>(TParent, Expression<Func<TParent, TProperty>>)

Gets image constraints for a specific property.

Declaration
public static ImageConstraints GetImageConstraints<TParent, TProperty>(this TParent parent, Expression<Func<TParent, TProperty>> expression) where TParent : class where TProperty : AdaptiveImage?
Parameters
Type Name Description
TParent parent
Expression<Func<TParent, TProperty>> expression
Returns
Type Description
ImageConstraints
Type Parameters
Name Description
TParent
TProperty
Exceptions
Type Condition
NotSupportedException

GetImageRenderSettings<TParent, TProperty>(TParent, Expression<Func<TParent, TProperty>>)

Gets an ImageRenderSettings object, with any proportions constraints applied, for a SingleImage property.

Declaration
public static ImageRenderSettings GetImageRenderSettings<TParent, TProperty>(this TParent parent, Expression<Func<TParent, TProperty>> expression) where TParent : class where TProperty : SingleImage?
Parameters
Type Name Description
TParent parent
Expression<Func<TParent, TProperty>> expression
Returns
Type Description
ImageRenderSettings

Default settings for rendering the image.

Type Parameters
Name Description
TParent
TProperty
Examples
  ImageRenderSettings renderSettings = currentContent.GetImageRenderSettings(x => x.MySingleImage)

GetImageRenderSettings<TParent, TProperty>(TParent, Expression<Func<TParent, TProperty>>, FormFactor)

Gets an ImageRenderSettings object, with any proportions constraints applied, for a specific form factor of an AdaptiveImage property.

Declaration
public static ImageRenderSettings GetImageRenderSettings<TParent, TProperty>(this TParent parent, Expression<Func<TParent, TProperty>> expression, FormFactor formFactor) where TParent : class where TProperty : AdaptiveImage?
Parameters
Type Name Description
TParent parent
Expression<Func<TParent, TProperty>> expression
FormFactor formFactor

Form factor for which render settings should be created.

Returns
Type Description
ImageRenderSettings

Default settings for rendering the image of a specific form factor.

Type Parameters
Name Description
TParent
TProperty
Examples
  ImageRenderSettings renderSettings = currentContent.GetImageRenderSettings(x => x.MyAdaptiveImage, FormFactor.Large)

GetProportionsConstraint<TParent>(TParent, string)

Used to get proportions constraints, if any, for a single image.

Declaration
public static ProportionsAttribute? GetProportionsConstraint<TParent>(this TParent parent, string singleImagePropertyName) where TParent : class
Parameters
Type Name Description
TParent parent
string singleImagePropertyName
Returns
Type Description
ProportionsAttribute
Type Parameters
Name Description
TParent

GetProportionsConstraint<TParent>(TParent, string, FormFactor)

Used to get proportions constraint, if any, for a specific form factor.

Declaration
public static ProportionsAttribute? GetProportionsConstraint<TParent>(this TParent parent, string adaptiveImagePropertyName, FormFactor formFactor) where TParent : class
Parameters
Type Name Description
TParent parent
string adaptiveImagePropertyName
FormFactor formFactor
Returns
Type Description
ProportionsAttribute
Type Parameters
Name Description
TParent

GetProportionsConstraint<TParent, TProperty>(TParent, Expression<Func<TParent, TProperty>>)

Get proportions contraint, if any, for a single form factor.

Declaration
public static ProportionsAttribute? GetProportionsConstraint<TParent, TProperty>(this TParent parent, Expression<Func<TParent, TProperty>> expression) where TParent : class where TProperty : SingleImage?
Parameters
Type Name Description
TParent parent
Expression<Func<TParent, TProperty>> expression
Returns
Type Description
ProportionsAttribute
Type Parameters
Name Description
TParent
TProperty

GetRequiredImageAttribute<TContent, TProperty>(TContent, Expression<Func<TContent, TProperty>>)

Used to get the RequiredImageAttribute attribute of a specific AdaptiveImage or SingleImage property.

Declaration
public static RequiredImageAttribute? GetRequiredImageAttribute<TContent, TProperty>(this TContent content, Expression<Func<TContent, TProperty>> expression)
Parameters
Type Name Description
TContent content
Expression<Func<TContent, TProperty>> expression
Returns
Type Description
RequiredImageAttribute
Type Parameters
Name Description
TContent
TProperty

GetSizeConstraint(IContentData, string)

Used to get size constraints, if any, for a single image.

Declaration
public static SizeAttribute? GetSizeConstraint(this IContentData content, string singleImagePropertyName)
Parameters
Type Name Description
IContentData content
string singleImagePropertyName
Returns
Type Description
SizeAttribute

GetSizeConstraint(IContentData, string, FormFactor)

Used to get size constraints, if any, for a specific form factor.

Declaration
public static SizeAttribute? GetSizeConstraint(this IContentData content, string adaptiveImagePropertyName, FormFactor formFactor)
Parameters
Type Name Description
IContentData content
string adaptiveImagePropertyName
FormFactor formFactor
Returns
Type Description
SizeAttribute

GetSizeConstraint<TContent, TProperty>(TContent, Expression<Func<TContent, TProperty>>)

Get size contraints, if any, for a single form factor.

Declaration
public static SizeAttribute? GetSizeConstraint<TContent, TProperty>(this TContent content, Expression<Func<TContent, TProperty>> expression) where TProperty : SingleImage?
Parameters
Type Name Description
TContent content
Expression<Func<TContent, TProperty>> expression
Returns
Type Description
SizeAttribute
Type Parameters
Name Description
TContent

Normally the content type that defines the SingleImage property

TProperty

The SingleImage property for which any size attribute should be resolved

HasFocalPoint(SingleImage?)

Checks if an image has an explicitly set focal point.

Declaration
public static bool HasFocalPoint(this SingleImage? image)
Parameters
Type Name Description
SingleImage image
Returns
Type Description
bool

IsCropped(SingleImage?)

Checks if image has been manually cropped.

Declaration
public static bool IsCropped(this SingleImage? image)
Parameters
Type Name Description
SingleImage image
Returns
Type Description
bool

IsSet(AdaptiveImage?)

Checks if adaptive image has an image set for all form factors.

Declaration
public static bool IsSet(this AdaptiveImage? image)
Parameters
Type Name Description
AdaptiveImage image
Returns
Type Description
bool

IsSet(SingleImage?)

Checks if the image has a valid image set.

Declaration
public static bool IsSet(this SingleImage? image)
Parameters
Type Name Description
SingleImage image
Returns
Type Description
bool

ToJson(AdaptiveImage?, Formatting)

Serializes an AdaptiveImage instance to JSON.

Declaration
public static string ToJson(this AdaptiveImage? image, Formatting formatting = Formatting.None)
Parameters
Type Name Description
AdaptiveImage image
Formatting formatting
Returns
Type Description
string

ToJson(SingleImage?, Formatting)

Serializes a SingleImage instance to JSON.

Declaration
public static string ToJson(this SingleImage? image, Formatting formatting = Formatting.None)
Parameters
Type Name Description
SingleImage image
Formatting formatting
Returns
Type Description
string
☀
☾
In this article
Back to top
Documentation applies to: Adaptive Images 2.x
☀
☾