I have created a validation attribute. And the IsValid method is as follows
<AttributeUsage(AttributeTargets.Field Or AttributeTargets.Property, AllowMultiple:=True)> _
Public NotInheritable Class BlaBlaAttribute
Inherits ValidationAttribute
Private ReadOnly _typeId As New Object()
...........
Protected Overrides Function IsValid(value As Object, validationContext As ValidationContext) As ValidationResult
Dim otherProperties = validationContext.ObjectType.GetProperties(BindingFlags.IgnoreCase Or BindingFlags.Public Or BindingFlags.Instance).ToList()
For Each item In otherProperties
Dim propItem = item
Dim attr As DisplayNameAttribute = DirectCast(Attribute.GetCustomAttribute(propItem, GetType(DisplayNameAttribute)), DisplayNameAttribute)
If attr Is Nothing Then
............
End If
Next
Return ValidationResult.Success
End Function
End Class
Thought, there are some display attributes but "attr" is always nothing. How to get other properties custom attributes? Any help would be highly appriciated
Aucun commentaire:
Enregistrer un commentaire