How to manipulate the 'value' when Setting a property value
I have the following property in a class:
'Language
Private _Language As String = ""
Public Property Language() As String
Get
If _Language <> "" Then
_Language = _Language.Remove(0, 9)
_Language = _Language.Remove(_Language.Length - 3, 3)
End If
Return _Language
End Get
Set(ByVal value As String)
_Language = "<![CDATA[" & value & "]]>"
End Set
End Property
The problem is that when I try to set the property like this:
myClass.Language = "English"
The property is set to "English"
and not to "<![CDATA[English]]>"
which is what I want.
What is the reason for that and how can I fix it?
Update: When placing a break point on End Set and use the Watch window to inspect the value of _Language 开发者_JAVA百科after setting the property to "English" it remains "English" and doesn't change.
I suspect that the property is actually being set correctly, but the context by which you are viewing the value is hiding the CDATA portion.
Please place a break point on End Set
and use your Watch 1
window to inspect the value of _Language after setting the property to English.
Your getter is wrong. It's modifying the property value! Change the setter value to something else is not recommended because then a Set/Get/Set will not work.
Basically you design is not great. I would reconsider this.
精彩评论