Class AllowedTypesAttribute
Assigns types that the property accept or restrict adding.
Inheritance
Implements
Namespace: EPiServer.DataAnnotations
Assembly: EPiServer.dll
Version: 8.11.0Syntax
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public sealed class AllowedTypesAttribute : ValidationAttribute, IMetadataAware
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 |
OnMetadataCreated(ModelMetadata)
Adds the allowed types to the metadata.
Declaration
public void OnMetadataCreated(ModelMetadata metadata)
Parameters
Type | Name | Description |
---|---|---|
System.Web.Mvc.ModelMetadata | metadata | The model metadata. |