Show / Hide Table of Contents

Class ProportionsAttribute

Used to specify image format proportions, for example Width=16 and Height=9 for a 16:9 wide format

Inheritance
object
Attribute
ValidationAttribute
ImageValidationAttribute
ProportionsAttribute
Implements
IProportions
IEquatable<ProportionsAttribute>
Inherited Members
ImageValidationAttribute.RequiresValidationContext
ImageValidationAttribute.FormFactor
ImageValidationAttribute.IsValid(object)
ValidationAttribute.FormatErrorMessage(string)
ValidationAttribute.GetValidationResult(object, ValidationContext)
ValidationAttribute.IsValid(object, ValidationContext)
ValidationAttribute.Validate(object, ValidationContext)
ValidationAttribute.Validate(object, string)
ValidationAttribute.ErrorMessage
ValidationAttribute.ErrorMessageResourceName
ValidationAttribute.ErrorMessageResourceType
ValidationAttribute.ErrorMessageString
Attribute.Equals(object)
Attribute.GetCustomAttribute(Assembly, Type)
Attribute.GetCustomAttribute(Assembly, Type, bool)
Attribute.GetCustomAttribute(MemberInfo, Type)
Attribute.GetCustomAttribute(MemberInfo, Type, bool)
Attribute.GetCustomAttribute(Module, Type)
Attribute.GetCustomAttribute(Module, Type, bool)
Attribute.GetCustomAttribute(ParameterInfo, Type)
Attribute.GetCustomAttribute(ParameterInfo, Type, bool)
Attribute.GetCustomAttributes(Assembly)
Attribute.GetCustomAttributes(Assembly, bool)
Attribute.GetCustomAttributes(Assembly, Type)
Attribute.GetCustomAttributes(Assembly, Type, bool)
Attribute.GetCustomAttributes(MemberInfo)
Attribute.GetCustomAttributes(MemberInfo, bool)
Attribute.GetCustomAttributes(MemberInfo, Type)
Attribute.GetCustomAttributes(MemberInfo, Type, bool)
Attribute.GetCustomAttributes(Module)
Attribute.GetCustomAttributes(Module, bool)
Attribute.GetCustomAttributes(Module, Type)
Attribute.GetCustomAttributes(Module, Type, bool)
Attribute.GetCustomAttributes(ParameterInfo)
Attribute.GetCustomAttributes(ParameterInfo, bool)
Attribute.GetCustomAttributes(ParameterInfo, Type)
Attribute.GetCustomAttributes(ParameterInfo, Type, bool)
Attribute.GetHashCode()
Attribute.IsDefaultAttribute()
Attribute.IsDefined(Assembly, Type)
Attribute.IsDefined(Assembly, Type, bool)
Attribute.IsDefined(MemberInfo, Type)
Attribute.IsDefined(MemberInfo, Type, bool)
Attribute.IsDefined(Module, Type)
Attribute.IsDefined(Module, Type, bool)
Attribute.IsDefined(ParameterInfo, Type)
Attribute.IsDefined(ParameterInfo, Type, bool)
Attribute.Match(object)
Attribute.TypeId
object.Equals(object, object)
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
Namespace: AdaptiveImages.Validation
Assembly: AdaptiveImages.dll
Syntax
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true, Inherited = true)]
public class ProportionsAttribute : ImageValidationAttribute, IProportions, IEquatable<ProportionsAttribute>

Constructors

ProportionsAttribute()

Defines a new proportions constraint.

Declaration
public ProportionsAttribute()
Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(FormFactor, string?)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(FormFactor formFactor, string? name)
Parameters
Type Name Description
FormFactor formFactor

One or more form factors this attribute applies to (bitwise OR supported), leave empty to make it apply to all form factors.

string name

Name to display in the UI when multiple proportion attributes apply to the same image/form factor. Language paths can be used.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(FormFactor, string?, bool)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(FormFactor formFactor, string? name, bool isDefault)
Parameters
Type Name Description
FormFactor formFactor

One or more form factors this attribute applies to (bitwise OR supported), leave empty to make it apply to all form factors.

string name

Name to display in the UI when multiple proportion attributes apply to the same image/form factor. Language paths can be used.

bool isDefault

Set to true to make this the default proportions if more than one attribute applies, otherwise the first proportions attribute will be used as the default.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(bool)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(bool isDefault)
Parameters
Type Name Description
bool isDefault

Set to true to make this the default proportions if more than one attribute applies, otherwise the first proportions attribute will be used as the default.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(int, int)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(int relativeWidth, int relativeHeight)
Parameters
Type Name Description
int relativeWidth

Relative width, for example 16 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

int relativeHeight

Relative height, for example 9 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(int, int, FormFactor)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(int relativeWidth, int relativeHeight, FormFactor formFactor)
Parameters
Type Name Description
int relativeWidth

Relative width, for example 16 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

int relativeHeight

Relative height, for example 9 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

FormFactor formFactor

One or more form factors this attribute applies to (bitwise OR supported), leave empty to make it apply to all form factors.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(int, int, FormFactor, bool)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(int relativeWidth, int relativeHeight, FormFactor formFactor, bool isDefault)
Parameters
Type Name Description
int relativeWidth

Relative width, for example 16 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

int relativeHeight

Relative height, for example 9 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

FormFactor formFactor

One or more form factors this attribute applies to (bitwise OR supported), leave empty to make it apply to all form factors.

bool isDefault

Set to true to make this the default proportions if more than one attribute applies, otherwise the first proportions attribute will be used as the default.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(int, int, FormFactor, string?)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(int relativeWidth, int relativeHeight, FormFactor formFactor, string? name)
Parameters
Type Name Description
int relativeWidth

Relative width, for example 16 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

int relativeHeight

Relative height, for example 9 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

FormFactor formFactor

One or more form factors this attribute applies to (bitwise OR supported), leave empty to make it apply to all form factors.

string name

Name to display in the UI when multiple proportion attributes apply to the same image/form factor. Language paths can be used.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(int, int, FormFactor, string?, bool)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(int relativeWidth, int relativeHeight, FormFactor formFactor, string? name, bool isDefault)
Parameters
Type Name Description
int relativeWidth

Relative width, for example 16 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

int relativeHeight

Relative height, for example 9 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

FormFactor formFactor

One or more form factors this attribute applies to (bitwise OR supported), leave empty to make it apply to all form factors.

string name

Name to display in the UI when multiple proportion attributes apply to the same image/form factor. Language paths can be used.

bool isDefault

Set to true to make this the default proportions if more than one attribute applies, otherwise the first proportions attribute will be used as the default.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(int, int, FormFactor, string?, bool, bool, bool)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(int relativeWidth, int relativeHeight, FormFactor formFactor, string? name, bool isDefault, bool allowCropping, bool allowFocalPoint)
Parameters
Type Name Description
int relativeWidth

Relative width, for example 16 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

int relativeHeight

Relative height, for example 9 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

FormFactor formFactor

One or more form factors this attribute applies to (bitwise OR supported), leave empty to make it apply to all form factors.

string name

Name to display in the UI when multiple proportion attributes apply to the same image/form factor. Language paths can be used.

bool isDefault

Set to true to make this the default proportions if more than one attribute applies, otherwise the first proportions attribute will be used as the default.

bool allowCropping

Whether user is allowed to manually crop the image.

bool allowFocalPoint

Whether user is allowed to manually set the focal point.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(int, int, bool)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(int relativeWidth, int relativeHeight, bool isDefault)
Parameters
Type Name Description
int relativeWidth

Relative width, for example 16 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

int relativeHeight

Relative height, for example 9 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

bool isDefault

Set to true to make this the default proportions if more than one attribute applies, otherwise the first proportions attribute will be used as the default.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(int, int, string?)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(int relativeWidth, int relativeHeight, string? name)
Parameters
Type Name Description
int relativeWidth

Relative width, for example 16 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

int relativeHeight

Relative height, for example 9 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

string name

Name to display in the UI when multiple proportion attributes apply to the same image/form factor. Language paths can be used.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(int, int, string?, bool)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(int relativeWidth, int relativeHeight, string? name, bool isDefault)
Parameters
Type Name Description
int relativeWidth

Relative width, for example 16 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

int relativeHeight

Relative height, for example 9 if specifying widescreen proportions like 16:9, or leave default to allow free-form cropping to any proportions.

string name

Name to display in the UI when multiple proportion attributes apply to the same image/form factor. Language paths can be used.

bool isDefault

Set to true to make this the default proportions if more than one attribute applies, otherwise the first proportions attribute will be used as the default.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(string?)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(string? name)
Parameters
Type Name Description
string name

Name to display in the UI when multiple proportion attributes apply to the same image/form factor. Language paths can be used.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

ProportionsAttribute(string?, bool)

Defines a new proportions constraint.

Declaration
public ProportionsAttribute(string? name, bool isDefault)
Parameters
Type Name Description
string name

Name to display in the UI when multiple proportion attributes apply to the same image/form factor. Language paths can be used.

bool isDefault

Set to true to make this the default proportions if more than one attribute applies, otherwise the first proportions attribute will be used as the default.

Remarks

The FormFactor property has no effect on SingleImage properties.

Exceptions
Type Condition
ArgumentException

Properties

AllowCropping

Gets or sets whether user is allowed to manually crop the image.

Declaration
public bool AllowCropping { get; set; }
Property Value
Type Description
bool

AllowFocalPoint

Gets or sets whether user is allowed to manually set the focal point.

Declaration
public bool AllowFocalPoint { get; set; }
Property Value
Type Description
bool

IsDefault

Gets or sets whether this should be the default proportions when more than one attribute applies to an image/form factor.

Declaration
public bool IsDefault { get; set; }
Property Value
Type Description
bool

IsFreeForm

Gets whether attribute represents free-form, i.e. no specific proportions constraint, meaning user should be able to crop image to any proportions.

Declaration
public bool IsFreeForm { get; }
Property Value
Type Description
bool

Name

Gets or sets name for the proportions, commonly displayed in UI when there are multiple proportions that apply to the same image/form factor. Language paths can be used.

Declaration
public string Name { get; set; }
Property Value
Type Description
string

Ratio

Gets the proportions ratio based on X and Y.

Declaration
public double Ratio { get; }
Property Value
Type Description
double
Remarks

A value of zero indicates free-form cropping without constraint.

X

Gets the width factor, for example 16 for 16:9 proportions.

Declaration
public int X { get; }
Property Value
Type Description
int
Remarks

Value of zero indicates free-form proportions without constraints.

Y

Gets the height factor, for example 9 for 16:9 proportions.

Declaration
public int Y { get; }
Property Value
Type Description
int
Remarks

Value of zero indicates free-form proportions without constraints.

Methods

Equals(ProportionsAttribute?)

Used to check whether to attributes are effectively the same.

Declaration
public bool Equals(ProportionsAttribute? other)
Parameters
Type Name Description
ProportionsAttribute other
Returns
Type Description
bool

ToString()

Represents human-readable proportions string.

Declaration
public override string ToString()
Returns
Type Description
string
Overrides
object.ToString()

Implements

IProportions
IEquatable<T>

Extension Methods

ImageExtensions.GetCultureSpecificImageAttribute<TContent, TProperty>(TContent, Expression<Func<TContent, TProperty>>)
ImageExtensions.GetImageConstraints<TParent>(TParent, string)
ImageExtensions.GetImageConstraints<TParent, TProperty>(TParent, Expression<Func<TParent, TProperty>>)
ImageExtensions.GetImageRenderSettings<TParent, TProperty>(TParent, Expression<Func<TParent, TProperty>>)
ImageExtensions.GetImageRenderSettings<TParent, TProperty>(TParent, Expression<Func<TParent, TProperty>>, FormFactor)
ImageExtensions.GetProportionsConstraint<TParent>(TParent, string)
ImageExtensions.GetProportionsConstraint<TParent>(TParent, string, FormFactor)
ImageExtensions.GetProportionsConstraint<TParent, TProperty>(TParent, Expression<Func<TParent, TProperty>>)
ImageExtensions.GetRequiredImageAttribute<TContent, TProperty>(TContent, Expression<Func<TContent, TProperty>>)
ImageExtensions.GetSizeConstraint<TContent, TProperty>(TContent, Expression<Func<TContent, TProperty>>)
☀
☾
In this article
Back to top
Documentation applies to: Adaptive Images 2.x
☀
☾