Try our conversational search powered by Generative AI!

Class AllowedTypesAttribute

Assigns types that the property accept or restrict adding.

Inheritance
System.Object
AllowedTypesAttribute
Namespace: EPiServer.DataAnnotations
Assembly: EPiServer.dll
Version: 11.20.7
Syntax
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public sealed class AllowedTypesAttribute : ValidationAttribute

Constructors

AllowedTypesAttribute()

Initializes a new instance of the AllowedTypesAttribute class.

Declaration
public AllowedTypesAttribute()

AllowedTypesAttribute(Type[])

Initializes a new instance of the AllowedTypesAttribute class.

Declaration
public AllowedTypesAttribute(params Type[] allowedTypes)
Parameters
Type Name Description
System.Type[] allowedTypes

The allowed types. The null value is replaced with IContentData.

AllowedTypesAttribute(Type[], Type[])

Initializes a new instance of the AllowedTypesAttribute class.

Declaration
public AllowedTypesAttribute(Type[] allowedTypes, Type[] restrictedTypes)
Parameters
Type Name Description
System.Type[] allowedTypes

The allowed types. The null value is replaced with IContentData.

System.Type[] restrictedTypes

The restricted types

AllowedTypesAttribute(Type[], Type[], String)

Initializes a new instance of the AllowedTypesAttribute class.

Declaration
public AllowedTypesAttribute(Type[] allowedTypes, Type[] restrictedTypes, string typesFormatSuffix)
Parameters
Type Name Description
System.Type[] allowedTypes

The allowed types. The null value is replaced with IContentData.

System.Type[] restrictedTypes

The restricted types

System.String typesFormatSuffix

The TypesFormatSuffix

Properties

AllowedTypes

Gets or sets the allowed types.

Declaration
public Type[] AllowedTypes { get; set; }
Property Value
Type Description
System.Type[]

The allowed types.

Remarks

Setting value null is treated as all IContentData types are allowed.

RestrictedTypes has presence over AllowedTypes meaning that if the instance is assignable to any type in RestrictedTypes then will it not be allowed regardless if the type is assignable to any type in AllowedTypes.

AllowedTypesFormatSuffix

Gets or sets the allowed types format suffix.

Declaration
[Obsolete("AllowedTypesFormatSuffix is replaced by TypesFormatSuffix and will be removed in the future versions. Use TypesFormatSuffix", false)]
public string AllowedTypesFormatSuffix { get; set; }
Property Value
Type Description
System.String

The allowed types format suffix.

RestrictedTypes

Gets types which the property is not allowed to contain.

Declaration
public Type[] RestrictedTypes { get; set; }
Property Value
Type Description
System.Type[]
Remarks

RestrictedTypes has presence over AllowedTypes meaning that if the instance is assignable to any type in RestrictedTypes then will it not be allowed regardless if the type is assignable to any type in AllowedTypes.

TypesFormatSuffix

Gets or sets types format suffix.

Declaration
public string TypesFormatSuffix { get; set; }
Property Value
Type Description
System.String

The types format suffix.

Methods

IsValid(Object, ValidationContext)

Declaration
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
Parameters
Type Name Description
System.Object value
System.ComponentModel.DataAnnotations.ValidationContext validationContext
Returns
Type Description
System.ComponentModel.DataAnnotations.ValidationResult

Extension Methods