Classes And ReadOnly Properties

J

Jumping Matt Flash

I'm trying to achieve a property within a class which returns a conditional
result dependent on the class members values.

I will explain..

Public Class Address

Private addrCountry As String

Public Property Country() As Country
Get
Return addrCountry
End Get
Set(ByVal newCountry As Country)
Me.addrCountry = newCountry
End Set
End Property

ReadOnly Property Errors() As Boolean
Get
If Me.Country.HasErrorsThen
Return True
Else : Return False
End If
End Get
End Property

End Class

The problem I'm facing is that when i return the class, in the case of my
ASP.NET web service, the Errors value is not included in my XML output. As
the variable is a readonly one i cannot set it to something to return it but
if i change it to not readonly i'll defeat the object of the Errors property
always returning the correct value.

TIA

Matt
 
C

Chris Dunaway

Jumping said:
The problem I'm facing is that when i return the class, in the case of my
ASP.NET web service, the Errors value is not included in my XML output. As

Does that matter? The Country property will be there and when the xml
is deserialized back into an instance of your class, the readonly
property should still work correctly. As you discovered, however,
ReadOnly and private properties are not serialized.

BTW: Your readonly property can be simplified. No need for an
If..Else construct:

ReadOnly Property Errors() As Boolean
Get
Return Me.Country.HasErrors
End Get
End Property
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top