I'm using the RegisterProperty from CSLA. I also have DisplayAttribute and DisplayNameAttribute on my properties attached to a resource. I notice that the .Name property of each of my RegisterProperty are cached. If I switch language, the .Name is not refreshed. This causes trouble since I'm using StringLengthAttribute and others to handle some business rules.
Is there a way to refresh the .Name or make sure the value isn't cached?
For now I decided to create my own attribute that takes the display name as parameter. I which there was a way to disable caching.
Public Class StringLengthExAttribute
Inherits StringLengthAttribute
Private _displayResourceName As String = ""
Public Sub New(ByVal maximumLength As Integer)
MyBase.New(maximumLength)
Me.ErrorMessageResourceName = "ruleExceedMaxCharacter"
Me.ErrorMessageResourceType = GetType(My.Resources)
End Sub
Public Sub New(ByVal displayResourceName As String, ByVal maximumLength As Integer)
MyBase.New(maximumLength)
_displayResourceName = displayResourceName
Me.ErrorMessageResourceName = "ruleExceedMaxCharacter"
Me.ErrorMessageResourceType = GetType(My.Resources)
End Sub
Public Overrides Function FormatErrorMessage(name As String) As String
If _displayResourceName <> "" Then
name = My.Resources.ResourceManager.GetString(_displayResourceName)
End If
Return MyBase.FormatErrorMessage(name)
End Function
End Class